tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1357407 - in /tomcat/trunk/java/org/apache/catalina: core/ApplicationContext.java ha/context/ReplicatedContext.java
Date Wed, 04 Jul 2012 21:03:47 GMT
Author: markt
Date: Wed Jul  4 21:03:46 2012
New Revision: 1357407

URL: http://svn.apache.org/viewvc?rev=1357407&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53498
Fix atomicity bugs in use of concurrent collections.
Based on a patch by Yu Lin.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1357407&r1=1357406&r2=1357407&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationContext.java Wed Jul  4 21:03:46
2012
@@ -169,7 +169,7 @@ public class ApplicationContext
     /**
      * The merged context initialization parameters for this Context.
      */
-    private Map<String,String> parameters =
+    private final ConcurrentHashMap<String,String> parameters =
         new ConcurrentHashMap<String,String>();
 
 
@@ -737,17 +737,14 @@ public class ApplicationContext
     public void removeAttribute(String name) {
 
         Object value = null;
-        boolean found = false;
 
         // Remove the specified attribute
         // Check for read only attribute
-        if (readOnlyAttributes.containsKey(name))
+        if (readOnlyAttributes.containsKey(name)){
             return;
-        found = attributes.containsKey(name);
-        if (found) {
-            value = attributes.get(name);
-            attributes.remove(name);
-        } else {
+        }
+        value = attributes.remove(name);
+        if (value == null) {
             return;
         }
 
@@ -1244,12 +1241,7 @@ public class ApplicationContext
 
     @Override
     public boolean setInitParameter(String name, String value) {
-        if (parameters.containsKey(name)) {
-            return false;
-        }
-
-        parameters.put(name, value);
-        return true;
+        return parameters.putIfAbsent(name, value) == null;
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java?rev=1357407&r1=1357406&r2=1357407&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java Wed Jul  4 21:03:46
2012
@@ -170,10 +170,12 @@ public class ReplicatedContext extends S
 
         @Override
         public Object getAttribute(String name) {
-            if (tomcatAttributes.containsKey(name) )
-                return tomcatAttributes.get(name);
-            else
+            Object obj = tomcatAttributes.get(name);
+            if (obj == null) {
                 return super.getAttribute(name);
+            } else {
+                return obj;
+            }
         }
 
         @SuppressWarnings("unchecked")



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


Mime
View raw message