Author: markt Date: Thu Oct 21 15:58:21 2010 New Revision: 1026042 URL: http://svn.apache.org/viewvc?rev=1026042&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50138 Fix threading issues
Modified: tomcat/trunk/java/org/apache/catalina/security/SecurityUtil.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/security/SecurityUtil.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/security/SecurityUtil.java?rev=1026042&r1=1026041&r2=1026042&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/security/SecurityUtil.java (original) +++ tomcat/trunk/java/org/apache/catalina/security/SecurityUtil.java Thu Oct 21 15:58:21 2010 @@ -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; Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1026042&r1=1026041&r2=1026042&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Thu Oct 21 15:58:21 2010 @@ -53,6 +53,10 @@ destroy the host'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"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org