Author: markt Date: Mon Nov 17 07:37:41 2014 New Revision: 1640084 URL: http://svn.apache.org/r1640084 Log: Fix BZ 57172. Throw an ISE with appropriate message if an attempt is made to load a resource from a web application class loader than has been stopped.
Modified: tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java Modified: tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties?rev=1640084&r1=1640083&r2=1640084&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/loader/LocalStrings.properties Mon Nov 17 07:37:41 2014 @@ -1,4 +1,4 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more +[# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 @@ -17,7 +17,7 @@ webappClassLoader.addPermisionNoCanonica webappClassLoader.addPermisionNoProtocol=The protocol [{0}] in the URL [{1}] is not supported so no read permission was granted for resources located at this URL webappClassLoader.illegalJarPath=Illegal JAR entry detected with name {0} webappClassLoader.jdbcRemoveFailed=JDBC driver de-registration failed for web application [{0}] -webappClassLoader.stopped=Illegal access: this web application instance has been stopped already. Could not load {0}. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact. +webappClassLoader.stopped=Illegal access: this web application instance has been stopped already. Could not load [{0}]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access. webappClassLoader.readError=Resource read error: Could not load {0}. webappClassLoader.clearJdbc=The web application [{0}] registered the JDBC driver [{1}] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. webappClassLoader.clearReferencesResourceBundlesCount=Removed [{0}] ResourceBundle references from the cache for web application [{1}] Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java?rev=1640084&r1=1640083&r2=1640084&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java Mon Nov 17 07:37:41 2014 @@ -917,6 +917,8 @@ public abstract class WebappClassLoaderB if (log.isDebugEnabled()) log.debug(" findResource(" + name + ")"); + checkStateForResourceLoading(name); + URL url = null; String path = nameToPath(name); @@ -965,6 +967,8 @@ public abstract class WebappClassLoaderB if (log.isDebugEnabled()) log.debug(" findResources(" + name + ")"); + checkStateForResourceLoading(name); + LinkedHashSet<URL> result = new LinkedHashSet<>(); String path = nameToPath(name); @@ -1015,6 +1019,9 @@ public abstract class WebappClassLoaderB if (log.isDebugEnabled()) log.debug("getResource(" + name + ")"); + + checkStateForResourceLoading(name); + URL url = null; // (1) Delegate to parent if requested @@ -1069,6 +1076,9 @@ public abstract class WebappClassLoaderB if (log.isDebugEnabled()) log.debug("getResourceAsStream(" + name + ")"); + + checkStateForResourceLoading(name); + InputStream stream = null; // (0) Check for a cached copy of this resource @@ -1299,17 +1309,27 @@ public abstract class WebappClassLoaderB protected void checkStateForClassLoading(String className) throws ClassNotFoundException { // It is not permitted to load new classes once the web application has // been stopped. - if (!state.isAvailable()) { - String msg = sm.getString("webappClassLoader.stopped", className); - IllegalStateException cause = new IllegalStateException(msg); + try { + checkStateForResourceLoading(className); + } catch (IllegalStateException ise) { ClassNotFoundException cnfe = new ClassNotFoundException(); - cnfe.initCause(cause); - log.info(msg, cnfe); + cnfe.initCause(ise); throw cnfe; } } + protected void checkStateForResourceLoading(String resource) throws IllegalStateException { + // It is not permitted to load resources once the web application has + // been stopped. + if (!state.isAvailable()) { + String msg = sm.getString("webappClassLoader.stopped", resource); + IllegalStateException ise = new IllegalStateException(msg); + log.info(msg, ise); + throw ise; + } + } + /** * Get the Permissions for a CodeSource. If this instance * of WebappClassLoaderBase is for a web application context, --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org