Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50078
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 14 Oct 2010 16:36:20 +0000 (16:36 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 14 Oct 2010 16:36:20 +0000 (16:36 +0000)
Thread safety in EL caches. Patch provided by  Takayoshi Kimura

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1022606 13f79535-47bb-0310-9956-ffa450edef68

java/javax/el/BeanELResolver.java
java/org/apache/el/lang/ExpressionBuilder.java
java/org/apache/el/util/ConcurrentCache.java

index dacb205..f93f4a6 100644 (file)
@@ -334,7 +334,9 @@ public class BeanELResolver extends ELResolver {
         public V get(K key) {
             V value = this.eden.get(key);
             if (value == null) {
-                value = this.longterm.get(key);
+                synchronized (longterm) {
+                    value = this.longterm.get(key);
+                }
                 if (value != null) {
                     this.eden.put(key, value);
                 }
@@ -344,7 +346,9 @@ public class BeanELResolver extends ELResolver {
         
         public void put(K key, V value) {
             if (this.eden.size() >= this.size) {
-                this.longterm.putAll(this.eden);
+                synchronized (longterm) {
+                    this.longterm.putAll(this.eden);
+                }
                 this.eden.clear();
             }
             this.eden.put(key, value);
index c72cf0c..079c733 100644 (file)
@@ -49,7 +49,8 @@ import org.apache.el.util.MessageFactory;
  */
 public final class ExpressionBuilder implements NodeVisitor {
 
-    private static final ConcurrentCache<String, Node> cache = new ConcurrentCache<String, Node>(5000);
+    private static final ConcurrentCache<String, Node> cache =
+        new ConcurrentCache<String, Node>(5000);
 
     private FunctionMapper fnMapper;
 
index 5515b0e..26029bb 100644 (file)
@@ -37,7 +37,9 @@ public final class ConcurrentCache<K,V> {
     public V get(K k) {
         V v = this.eden.get(k);
         if (v == null) {
-            v = this.longterm.get(k);
+            synchronized (longterm) {
+                v = this.longterm.get(k);
+            }
             if (v != null) {
                 this.eden.put(k, v);
             }
@@ -47,7 +49,9 @@ public final class ConcurrentCache<K,V> {
 
     public void put(K k, V v) {
         if (this.eden.size() >= size) {
-            this.longterm.putAll(this.eden);
+            synchronized (longterm) {
+                this.longterm.putAll(this.eden);
+            }
             this.eden.clear();
         }
         this.eden.put(k, v);