From: markt Date: Sat, 4 Nov 2006 21:21:07 +0000 (+0000) Subject: Port fix bug 37458. Remove the possibility of some NPE and IAE issues. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8131ede596f84e7b9a2b0a306fb8d9ae914d8cbf;p=tomcat7.0 Port fix bug 37458. Remove the possibility of some NPE and IAE issues. Note for Remy - you had some ideas to improve this patch. git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@471263 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/loader/WebappClassLoader.java b/java/org/apache/catalina/loader/WebappClassLoader.java index a7648da03..8b29ffe33 100644 --- a/java/org/apache/catalina/loader/WebappClassLoader.java +++ b/java/org/apache/catalina/loader/WebappClassLoader.java @@ -1758,63 +1758,58 @@ public class WebappClassLoader if (clazz != null) return clazz; - synchronized (this) { + synchronized (entry) { if (entry.binaryContent == null && entry.loadedClass == null) throw new ClassNotFoundException(name); - } - - // Looking up the package - String packageName = null; - int pos = name.lastIndexOf('.'); - if (pos != -1) - packageName = name.substring(0, pos); - Package pkg = null; - - if (packageName != null) { - - pkg = getPackage(packageName); - - // Define the package (if null) - if (pkg == null) { - if (entry.manifest == null) { - definePackage(packageName, null, null, null, null, null, - null, null); - } else { - definePackage(packageName, entry.manifest, entry.codeBase); + // Looking up the package + String packageName = null; + int pos = name.lastIndexOf('.'); + if (pos != -1) + packageName = name.substring(0, pos); + + Package pkg = null; + + if (packageName != null) { + synchronized (this) { + pkg = getPackage(packageName); + + // Define the package (if null) + if (pkg == null) { + if (entry.manifest == null) { + definePackage(packageName, null, null, null, null, + null, null, null); + } else { + definePackage(packageName, entry.manifest, + entry.codeBase); + } + } } } - - } - - // Create the code source object - CodeSource codeSource = - new CodeSource(entry.codeBase, entry.certificates); - - if (securityManager != null) { - - // Checking sealing - if (pkg != null) { - boolean sealCheck = true; - if (pkg.isSealed()) { - sealCheck = pkg.isSealed(entry.codeBase); - } else { - sealCheck = (entry.manifest == null) - || !isPackageSealed(packageName, entry.manifest); + + if (securityManager != null) { + + // Checking sealing + if (pkg != null) { + boolean sealCheck = true; + if (pkg.isSealed()) { + sealCheck = pkg.isSealed(entry.codeBase); + } else { + sealCheck = (entry.manifest == null) + || !isPackageSealed(packageName, entry.manifest); + } + if (!sealCheck) + throw new SecurityException + ("Sealing violation loading " + name + " : Package " + + packageName + " is sealed."); } - if (!sealCheck) - throw new SecurityException - ("Sealing violation loading " + name + " : Package " - + packageName + " is sealed."); + } - } - - synchronized (this) { if (entry.loadedClass == null) { clazz = defineClass(name, entry.binaryContent, 0, entry.binaryContent.length, - codeSource); + new CodeSource(entry.codeBase, entry.certificates)); entry.loadedClass = clazz; entry.binaryContent = null; entry.source = null;