From: markt Date: Thu, 21 Oct 2010 15:58:21 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50138 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b451cbc5f869352675b0c3a16c47816b71af5b29;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50138 Fix threading issues git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1026042 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/security/SecurityUtil.java b/java/org/apache/catalina/security/SecurityUtil.java index fff9e5c53..8aad81a96 100644 --- a/java/org/apache/catalina/security/SecurityUtil.java +++ b/java/org/apache/catalina/security/SecurityUtil.java @@ -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 objectCache = - new HashMap(); + private static final Map objectCache = + new ConcurrentHashMap(); 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 pea = new PrivilegedExceptionAction(){ + @Override public Void run() throws Exception{ method.invoke(targetObject, targetArguments); return null; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index cf4fd8105..1992d1435 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -53,6 +53,10 @@ destroy the host's pipeline twice. Patch provided by Eiji Takahashi. (markt) + + 50138: Fix threading issues in + org.apache.catalina.security.SecurityUtil. (markt) +