You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/09/12 09:00:49 UTC

[tomcat] branch main updated: Fix locking - found by SpotBugs

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 042235e141 Fix locking - found by SpotBugs
042235e141 is described below

commit 042235e141a1d285426a4a7ffbc6d3ce0d249a6a
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Sep 12 10:00:40 2022 +0100

    Fix locking - found by SpotBugs
---
 java/org/apache/catalina/realm/MemoryRealm.java | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/java/org/apache/catalina/realm/MemoryRealm.java b/java/org/apache/catalina/realm/MemoryRealm.java
index 7c1671e621..2584438291 100644
--- a/java/org/apache/catalina/realm/MemoryRealm.java
+++ b/java/org/apache/catalina/realm/MemoryRealm.java
@@ -54,6 +54,7 @@ public class MemoryRealm  extends RealmBase {
      * The Digester we will use to process in-memory database files.
      */
     private static Digester digester = null;
+    private static final Object digesterLock = new Object();
 
 
     /**
@@ -197,18 +198,18 @@ public class MemoryRealm  extends RealmBase {
      * @return a configured <code>Digester</code> to use for processing
      * the XML input file, creating a new one if necessary.
      */
-    protected synchronized Digester getDigester() {
-        if (digester == null) {
-            digester = new Digester();
-            digester.setValidating(false);
-            try {
-                digester.setFeature(
-                        "http://apache.org/xml/features/allow-java-encodings",
-                        true);
-            } catch (Exception e) {
-                log.warn(sm.getString("memoryRealm.xmlFeatureEncoding"), e);
+    protected Digester getDigester() {
+        synchronized (digesterLock) {
+            if (digester == null) {
+                digester = new Digester();
+                digester.setValidating(false);
+                try {
+                    digester.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
+                } catch (Exception e) {
+                    log.warn(sm.getString("memoryRealm.xmlFeatureEncoding"), e);
+                }
+                digester.addRuleSet(new MemoryRuleSet());
             }
-            digester.addRuleSet(new MemoryRuleSet());
         }
         return digester;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org