Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50138
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 21 Oct 2010 15:58:21 +0000 (15:58 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 21 Oct 2010 15:58:21 +0000 (15:58 +0000)
Fix threading issues

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

java/org/apache/catalina/security/SecurityUtil.java
webapps/docs/changelog.xml

index fff9e5c..8aad81a 100644 (file)
@@ -23,7 +23,8 @@ import java.lang.reflect.Method;
 import java.security.Principal;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
-import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.security.auth.Subject;
 import javax.servlet.Filter;
@@ -66,8 +67,8 @@ public final class SecurityUtil{
     /**
      * Cache every object for which we are creating method on it.
      */
-    private static HashMap<Object,Method[]> objectCache =
-        new HashMap<Object,Method[]>();
+    private static final Map<Object,Method[]> objectCache =
+        new ConcurrentHashMap<Object,Method[]>();
         
     private static final org.apache.juli.logging.Log log=
         org.apache.juli.logging.LogFactory.getLog( SecurityUtil.class );
@@ -147,21 +148,20 @@ public final class SecurityUtil{
         throws java.lang.Exception{
 
         Method method = null;
-        Method[] methodsCache = null;
-        if(objectCache.containsKey(targetObject)){
-            methodsCache = objectCache.get(targetObject);
+        Method[] methodsCache = objectCache.get(targetObject);
+        if(methodsCache == null) {
+            method = createMethodAndCacheIt(methodsCache,
+                                            methodName,
+                                            targetObject,
+                                            targetType);                     
+        } else {
             method = findMethod(methodsCache, methodName);
-            if (method == null){
+            if (method == null) {
                 method = createMethodAndCacheIt(methodsCache,
                                                 methodName,
                                                 targetObject,
                                                 targetType);
             }
-        } else {
-            method = createMethodAndCacheIt(methodsCache,
-                                            methodName,
-                                            targetObject,
-                                            targetType);                     
         }
 
         execute(method, targetObject, targetArguments, principal);
@@ -226,23 +226,22 @@ public final class SecurityUtil{
                                      final Object[] targetArguments,
                                      Principal principal) 
         throws java.lang.Exception{
+        
         Method method = null;
-
-        Method[] methodsCache = null;
-        if(objectCache.containsKey(targetObject)){
-            methodsCache = objectCache.get(targetObject);
+        Method[] methodsCache = objectCache.get(targetObject);
+        if(methodsCache == null) {
+            method = createMethodAndCacheIt(methodsCache,
+                                            methodName,
+                                            targetObject,
+                                            targetType);                     
+        } else {
             method = findMethod(methodsCache, methodName);
-            if (method == null){
+            if (method == null) {
                 method = createMethodAndCacheIt(methodsCache,
                                                 methodName,
                                                 targetObject,
                                                 targetType);
             }
-        } else {
-            method = createMethodAndCacheIt(methodsCache,
-                                            methodName,
-                                            targetObject,
-                                            targetType);                     
         }
 
         execute(method, targetObject, targetArguments, principal);
@@ -271,6 +270,7 @@ public final class SecurityUtil{
             Subject subject = null;
             PrivilegedExceptionAction<Void> pea =
                 new PrivilegedExceptionAction<Void>(){
+                    @Override
                     public Void run() throws Exception{
                        method.invoke(targetObject, targetArguments);
                        return null;
index cf4fd81..1992d14 100644 (file)
         destroy the host&apos;s pipeline twice. Patch provided by Eiji
         Takahashi. (markt)
       </fix>
+      <fix>
+        <bug>50138</bug>: Fix threading issues in
+        <code>org.apache.catalina.security.SecurityUtil</code>. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">