velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1855453 - /velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java
Date Wed, 13 Mar 2019 19:59:21 GMT
Author: cbrisson
Date: Wed Mar 13 19:59:21 2019
New Revision: 1855453

URL: http://svn.apache.org/viewvc?rev=1855453&view=rev
Log:
[tools/generic] Fix small concurrency issue in safe tool initialization

Modified:
    velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java?rev=1855453&r1=1855452&r2=1855453&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/SafeConfig.java
Wed Mar 13 19:59:21 2019
@@ -26,6 +26,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * <p>Implements common logic and constants for tools which automatically
@@ -76,7 +77,7 @@ public class SafeConfig
      */
     public static final String USE_CLASS_LOGGER_KEY = "useClassLogger";
 
-    private boolean configLocked = false;
+    private AtomicBoolean configLocked = new AtomicBoolean(false);
     private boolean safeMode = false;
 
     protected Logger log = null;
@@ -87,7 +88,7 @@ public class SafeConfig
      */
     protected void setLockConfig(boolean lock)
     {
-        this.configLocked = lock;
+        this.configLocked.set(lock);
     }
 
     /**
@@ -106,7 +107,7 @@ public class SafeConfig
      */
     public boolean isConfigLocked()
     {
-        return this.configLocked;
+        return this.configLocked.get();
     }
 
     /**
@@ -134,19 +135,25 @@ public class SafeConfig
     {
         if (!isConfigLocked())
         {
-            ValueParser values = new ValueParser(params);
-
-            // set up logger
-            initLogger(values);
-
-            // call configure
-            configure(values);
-
-            setSafeMode(values.getBoolean(SAFE_MODE_KEY, true));
-
-            // check under the new key
-            Boolean lock = values.getBoolean(LOCK_CONFIG_KEY, Boolean.TRUE);
-            setLockConfig(lock.booleanValue());
+            synchronized (this)
+            {
+                if (!isConfigLocked())
+                {
+                    ValueParser values = new ValueParser(params);
+
+                    // set up logger
+                    initLogger(values);
+
+                    // call configure
+                    configure(values);
+
+                    setSafeMode(values.getBoolean(SAFE_MODE_KEY, true));
+
+                    // check under the new key
+                    Boolean lock = values.getBoolean(LOCK_CONFIG_KEY, Boolean.TRUE);
+                    setLockConfig(lock.booleanValue());
+                }
+            }
         }
     }
 



Mime
View raw message