velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1834392 - /velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/Toolbox.java
Date Tue, 26 Jun 2018 02:42:16 GMT
Author: cbrisson
Date: Tue Jun 26 02:42:16 2018
New Revision: 1834392

URL: http://svn.apache.org/viewvc?rev=1834392&view=rev
Log:
[tools] Fix initialization race condition VELTOOLS-157

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

Modified: velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/Toolbox.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/Toolbox.java?rev=1834392&r1=1834391&r2=1834392&view=diff
==============================================================================
--- velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/Toolbox.java
(original)
+++ velocity/tools/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/Toolbox.java
Tue Jun 26 02:42:16 2018
@@ -102,14 +102,20 @@ public class Toolbox implements java.io.
 
     public Object get(String key, String path, Map<String,Object> context)
     {
-        Object tool = null;
-        if (cache != null)
-        {
-            tool = getFromCache(key, path);
-        }
+        /* try the cache */
+        Object tool = getFromCache(key, path);
+
         if (tool == null)
         {
-            tool = getFromInfo(key, path, context);
+            /* synchronize and try again */
+            synchronized (this)
+            {
+                tool = getFromCache(key, path);
+                if (tool == null)
+                {
+                    tool = getFromInfo(key, path, context);
+                }
+            }
         }
         return tool;
     }



Mime
View raw message