Author: markt Date: Mon Nov 17 07:48:39 2014 New Revision: 1640087 URL: http://svn.apache.org/r1640087 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=57172 Provide a better error message if an attempt is made access a resource through a web application class loader that has been stopped.
Modified: tomcat/tc8.0.x/trunk/ (props changed) tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc8.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1640084 Modified: tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties?rev=1640087&r1=1640086&r2=1640087&view=diff ============================================================================== --- tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties (original) +++ tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties Mon Nov 17 07:48:39 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/tc8.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java?rev=1640087&r1=1640086&r2=1640087&view=diff ============================================================================== --- tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java (original) +++ tomcat/tc8.0.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java Mon Nov 17 07:48:39 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, Modified: tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml?rev=1640087&r1=1640086&r2=1640087&view=diff ============================================================================== --- tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml Mon Nov 17 07:48:39 2014 @@ -48,6 +48,11 @@ <subsection name="Catalina"> <changelog> <fix> + <bug>57172</bug>: Provide a better error message if an attempt is made + access a resource through a web application class loader that has been + stopped. (markt) + </fix> + <fix> <bug>57187</bug>: Regression handling the special * URL. (remm) </fix> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org