Fix https://issues.apache.org/bugzilla/attachment.cgi?id=23066
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 2 Jan 2009 14:24:35 +0000 (14:24 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 2 Jan 2009 14:24:35 +0000 (14:24 +0000)
Sync issue leads to NPE in rare circumstances
Patch provided by Konstantin Kolinko

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

java/org/apache/catalina/loader/WebappClassLoader.java

index 5a91145..6988bc1 100644 (file)
@@ -1794,7 +1794,11 @@ public class WebappClassLoader
             return clazz;
 
         synchronized (this) {
-            if (entry.binaryContent == null && entry.loadedClass == null)
+            clazz = entry.loadedClass;
+            if (clazz != null)
+                return clazz;
+
+            if (entry.binaryContent == null)
                 throw new ClassNotFoundException(name);
 
             // Looking up the package
@@ -1843,26 +1847,22 @@ public class WebappClassLoader
     
             }
 
-            if (entry.loadedClass == null) {
-                try {
-                    clazz = defineClass(name, entry.binaryContent, 0,
-                            entry.binaryContent.length, 
-                            new CodeSource(entry.codeBase, entry.certificates));
-                } catch (UnsupportedClassVersionError ucve) {
-                    throw new UnsupportedClassVersionError(
-                            ucve.getLocalizedMessage() + " " +
-                            sm.getString("webappClassLoader.wrongVersion",
-                                    name));
-                }
-                entry.loadedClass = clazz;
-                entry.binaryContent = null;
-                entry.source = null;
-                entry.codeBase = null;
-                entry.manifest = null;
-                entry.certificates = null;
-            } else {
-                clazz = entry.loadedClass;
+            try {
+                clazz = defineClass(name, entry.binaryContent, 0,
+                        entry.binaryContent.length, 
+                        new CodeSource(entry.codeBase, entry.certificates));
+            } catch (UnsupportedClassVersionError ucve) {
+                throw new UnsupportedClassVersionError(
+                        ucve.getLocalizedMessage() + " " +
+                        sm.getString("webappClassLoader.wrongVersion",
+                                name));
             }
+            entry.loadedClass = clazz;
+            entry.binaryContent = null;
+            entry.source = null;
+            entry.codeBase = null;
+            entry.manifest = null;
+            entry.certificates = null;
         }
         
         return clazz;