Top Description Inners Fields Constructors Methods
org.apache.catalina.loader

public abstract Class WebappClassLoaderBase

extends URLClassLoader
implements Lifecycle, InstrumentableClassLoader, WebappProperties, PermissionCheck
Class Inheritance
All Implemented Interfaces
org.apache.tomcat.util.security.PermissionCheck, org.apache.juli.WebappProperties, org.apache.tomcat.InstrumentableClassLoader, org.apache.catalina.Lifecycle
Known Direct Subclasses
org.apache.catalina.loader.ParallelWebappClassLoader, org.apache.catalina.loader.WebappClassLoader
Imports
java.io.ByteArrayInputStream, .ByteArrayOutputStream, .File, .FilePermission, .IOException, .InputStream, java.lang.instrument.ClassFileTransformer, .IllegalClassFormatException, java.lang.ref.Reference, java.lang.reflect.Field, .InaccessibleObjectException, .Method, java.net.URI, .URISyntaxException, .URL, .URLClassLoader, java.security.AccessControlException, .AccessController, .CodeSource, .Permission, .PermissionCollection, .Policy, .PrivilegedAction, .ProtectionDomain, java.security.cert.Certificate, java.util.ArrayList, .Arrays, .Collection, .Collections, .ConcurrentModificationException, .Date, .Enumeration, .HashMap, .Iterator, .LinkedHashSet, .List, .Map, .Map.Entry, .NoSuchElementException, java.util.concurrent.ConcurrentHashMap, .CopyOnWriteArrayList, java.util.jar.Attributes, .Attributes.Name, .Manifest, org.apache.catalina.Container, .Globals, .Lifecycle, .LifecycleException, .LifecycleListener, .LifecycleState, .WebResource, .WebResourceRoot, org.apache.catalina.webresources.TomcatURLStreamHandlerFactory, org.apache.juli.WebappProperties, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.InstrumentableClassLoader, org.apache.tomcat.util.ExceptionUtils, .IntrospectionUtils, org.apache.tomcat.util.compat.JreCompat, org.apache.tomcat.util.res.StringManager, org.apache.tomcat.util.security.PermissionCheck, org.apache.tomcat.util.threads.ThreadPoolExecutor

Specialized web application class loader.

This class loader is a full reimplementation of the URLClassLoader from the JDK. It is designed to be fully compatible with a normal URLClassLoader, although its internal behavior may be completely different.

Implementation Note

- By default, this class loader follows the delegation model required by the specification. The bootstrap class loader will be queried first, then the local repositories, and only then delegation to the parent class loader will occur. This allows the web application to override any shared class except the classes from J2SE. Special handling is provided from the JAXP XML parser interfaces, the JNDI interfaces, and the classes from the servlet API, which are never loaded from the webapp repositories. The delegate property allows an application to modify this behavior to move the parent class loader ahead of the local repositories.

Implementation Note

- Due to limitations in Jasper compilation technology, any repository which contains classes from the servlet API will be ignored by the class loader.

Implementation Note

- The class loader generates source URLs which include the full JAR URL when a class is loaded from a JAR file, which allows setting security permission at the class level, even when a class is contained inside a JAR.

Implementation Note

- Local repositories are searched in the order they are added via the initial constructor.

Implementation Note

- No check for sealing violations or security is made unless a security manager is present.

Implementation Note

- As of 8.0, this class loader implements InstrumentableClassLoader, permitting web application classes to instrument other classes in the same web application. It does not permit instrumentation of system or container classes or classes in other web apps.

Authors
Remy Maucherat, Craig R. McClanahan

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
protected class
protected static class
private class
protected class

Field Summary

Modifier and TypeField and Description
private static final String
private boolean
clearReferencesHttpClientKeepAliveThread

If an HttpClient keep-alive timer thread has been started by this web application and is still running, should Tomcat change the context class loader from the current ClassLoader to ClassLoader#getParent() to prevent a memory leak?

private boolean
private boolean
clearReferencesObjectStreamClassCaches

Should Tomcat attempt to clear references to classes loaded by this class loader from the ObjectStreamClass caches?

private boolean
clearReferencesRmiTargets

Enables the RMI Target memory leak detection to be controlled.

private boolean
clearReferencesStopThreads

Should Tomcat attempt to terminate threads that have been started by the web application?

private boolean
clearReferencesStopTimerThreads

Should Tomcat attempt to terminate any java.util.TimerThreads that have been started by the web application?

private boolean
clearReferencesThreadLocals

Should Tomcat attempt to clear references to classes loaded by this class loader from ThreadLocals?

protected boolean
delegate

Should this class loader delegate to the parent class loader before searching its own repositories (i.e. the usual Java2 delegation model)?

private boolean
hasExternalRepositories

Flag that indicates that addURL(URL) has been called which creates a requirement to check the super class when searching for resources.

private final Map<String, Long>
private ClassLoader
javaseClassLoader

The bootstrap class loader used to load the JavaSE classes.

private static final List<String>
JVM_THREAD_GROUP_NAMES

List of ThreadGroup names to ignore when scanning for web application started threads that need to be shut down.

private static final String
protected final HashMap<String, PermissionCollection>
loaderPC

The PermissionCollection for each CodeSource for a web application context.

private List<URL>
localRepositories

Repositories managed by this class rather than the super class.

private static final Log
protected final ClassLoader
parent

Hides java.lang.ClassLoader.parent.

The parent class loader.
protected final ArrayList<Permission>
permissionList

A list of read File Permission's required if this loader is for a web application context.

protected final Map<String, ResourceEntry>
resourceEntries

The cache of ResourceEntry for classes and resources we have loaded, keyed by resource path, not binary name.

protected WebResourceRoot
resources

Associated web resources for this webapp.

protected final SecurityManager
securityManager

Deprecated as a consequence of SecurityManager being deprecated.
Instance of the SecurityManager installed.
private boolean
skipMemoryLeakChecksOnJvmShutdown

Should Tomcat skip the memory leak checks when the web application is stopped as part of the process of shutting down the JVM?

protected static final StringManager
sm

The string manager for this package.

private volatile LifecycleState
private final List<ClassFileTransformer>
transformers

Holds the class file transformers decorating this class loader.

Constructor Summary

AccessConstructor and Description
protected
WebappClassLoaderBase()

Construct a new ClassLoader with no defined repositories and no parent ClassLoader.

protected
WebappClassLoaderBase(ClassLoader
Our parent class loader
parent
)

Construct a new ClassLoader with no defined repositories and the given parent ClassLoader.

Method Summary

Modifier and TypeMethod and Description
public void
addLifecycleListener(LifecycleListener
The listener to add
listener
)

Implements org.apache.catalina.Lifecycle.addLifecycleListener.

Add a lifecycle event listener to this component.

pack-priv void
addPermission(URL
URL for a file or directory on local system
url
)

If there is a Java SecurityManager create a read permission for the target of the given URL as appropriate.

pack-priv void
addPermission(Permission
The permission
permission
)

If there is a Java SecurityManager create a Permission.

public void
addTransformer(ClassFileTransformer
The transformer to add to the class loader
transformer
)

Implements org.apache.tomcat.InstrumentableClassLoader.addTransformer.

Adds the specified class file transformer to this class loader.

protected void
addURL(URL
the URL to be added to the search path of URLs
url
)

Overrides java.net.URLClassLoader.addURL.

Appends the specified URL to the list of URLs to search for classes and resources.

private String
binaryNameToPath(String binaryName, boolean withLeadingSlash)

public boolean
check(Permission
The permission to test
permission
)

Implements org.apache.tomcat.util.security.PermissionCheck.check.

Does this component have the given permission?

protected void
protected void
private void
checkThreadLocalMapForLeaks(Object map, Field internalTableField)

Analyzes the given thread local map object.

private void
private void
clearCache(Class<?> target, String mapName)

protected void
clearReferences()

Clear references.

private void
clearReferencesJdbc()

Deregister any JDBC drivers registered by the webapp that the webapp forgot.

private void
private void
clearReferencesRmiTargets()

This depends on the internals of the Sun JVM so it does everything by reflection.

private void
private void
protected void
public void
destroy()

Implements org.apache.catalina.Lifecycle.destroy.

Prepare to discard the object.

protected final Class<?>
doDefineClass(String name, byte[] b, int off, int len, ProtectionDomain protectionDomain)

protected boolean

Returns:

true if the class should be filtered
filter
(String
class name
name
,
boolean
true if name is a class name, false if name is a resource name
isClassName
)

Filter classes.

public Class<?>
findClass(String
The binary name of the class to be loaded
name
)

Overrides java.net.URLClassLoader.findClass.

Find the specified class in our local repositories, if possible.

protected Class<?>

Returns:

the loaded class, or null if the class isn't found
findClassInternal
(String
The binary name of the class to be loaded
name
)

Find specified class in local repositories.

public LifecycleListener[]
findLifecycleListeners()

Implements org.apache.catalina.Lifecycle.findLifecycleListeners.

Get the lifecycle listeners associated with this lifecycle.

protected Class<?>

Returns:

a loaded class
findLoadedClass0
(String
The binary name of the resource to return
name
)

Hides java.lang.ClassLoader.findLoadedClass0.

Finds the class with the given name if it has previously been loaded and cached by this class loader, and return the Class object.

public URL
findResource(final String
Name of the resource to be found
name
)

Overrides java.net.URLClassLoader.findResource.

Find the specified resource in our local repository, and return a URL referring to it, or null if this resource cannot be found.

public Enumeration<URL>
findResources(String
Name of the resources to be found
name
)

Overrides java.net.URLClassLoader.findResources.

Return an enumeration of URLs representing all of the resources with the given name.

public boolean

Returns:

the clearReferencesHttpClientKeepAliveThread flag for this Context.
getClearReferencesHttpClientKeepAliveThread
()

public boolean

Returns:

the clearReferencesLogFactoryRelease flag for this Context.
getClearReferencesLogFactoryRelease
()

public boolean
public boolean
public boolean

Returns:

the clearReferencesStopThreads flag for this Context.
getClearReferencesStopThreads
()

public boolean

Returns:

the clearReferencesStopTimerThreads flag for this Context.
getClearReferencesStopTimerThreads
()

public boolean
public String

Returns:

the context name for this class loader.
getContextName
()

private String
public boolean

Returns:

true if the class lookup will delegate to the parent first. The default in Tomcat is false.
getDelegate
()

Return the "delegate first" flag for this class loader.

public String
getHostName()

Implements org.apache.juli.WebappProperties.getHostName.

Returns a name for the logging system to use for the Host where the web application, if any, associated with the class loader is deployed.

protected ClassLoader
protected PermissionCollection

Returns:

PermissionCollection for CodeSource
getPermissions
(CodeSource
where the code was loaded from
codeSource
)

Overrides java.net.URLClassLoader.getPermissions.

Get the Permissions for a CodeSource.

private String
public URL
getResource(String
Name of the resource to return a URL for
name
)

Overrides java.lang.ClassLoader.getResource.

Find the resource with the given name.

public InputStream
getResourceAsStream(String
Name of the resource to return an input stream for
name
)

Overrides java.net.URLClassLoader.getResourceAsStream.

Find the resource with the given name, and return an input stream that can be used for reading it.

public Enumeration<URL>
getResources(String
The resource name
name
)

Overrides java.lang.ClassLoader.getResources.

Finds all the resources with the given name.

public String
getServiceName()

Implements org.apache.juli.WebappProperties.getServiceName.

Returns a name for the logging system to use for the Service where the Host, if any, associated with the class loader is deployed.

public boolean
private String
public LifecycleState

Returns:

The current state of the source component.
getState
()

Implements org.apache.catalina.Lifecycle.getState.

Obtain the current state of the source component.

public String
getStateName()

Implements org.apache.catalina.Lifecycle.getStateName.

Obtain a textual representation of the current component state.

private Thread[]
public URL[]
getURLs()

Overrides java.net.URLClassLoader.getURLs.

Returns the search path of URLs for loading classes and resources.

public String
getWebappName()

Implements org.apache.juli.WebappProperties.getWebappName.

Returns a name for the logging system to use for the web application, if any, associated with the class loader.

public boolean
hasLoggingConfig()

Implements org.apache.juli.WebappProperties.hasLoggingConfig.

Enables JULI to determine if the web application includes a local configuration without JULI having to look for the file which it may not have permission to do when running under a SecurityManager.

public void
init()

Implements org.apache.catalina.Lifecycle.init.

Prepare the component for starting.

protected boolean

Returns:

true if the manifest associated says it is sealed
isPackageSealed
(String
Path name to check
name
,
Manifest
Associated manifest
man
)

Returns true if the specified package name is sealed according to the given manifest.

private boolean
public Class<?>
loadClass(String
The binary name of the class to be loaded
name
)

Overrides java.lang.ClassLoader.loadClass.

Load the class with the specified name.

public Class<?>
loadClass(String
The binary name of the class to be loaded
name
,
boolean
If true then resolve the class
resolve
)

Overrides java.lang.ClassLoader.loadClass.

Load the class with the specified name, searching using the following algorithm until it finds and returns the class.

private boolean

Returns:

true if o has been loaded by the current classloader or one of its descendants.
loadedByThisOrChild
(Object
object to test, may be null
o
)

public boolean

Returns:

true if there's been a modification
modified
()

Have one or more classes or resources been modified so that a reload is appropriate?

private String
protected void
refreshPolicy()

Refresh the system policy file, to pick up eventual changes.

public void
removeLifecycleListener(LifecycleListener
The listener to remove
listener
)

Implements org.apache.catalina.Lifecycle.removeLifecycleListener.

Remove a lifecycle event listener from this component.

public void
removeTransformer(ClassFileTransformer
The transformer to remove
transformer
)

Implements org.apache.tomcat.InstrumentableClassLoader.removeTransformer.

Removes the specified class file transformer from this class loader.

public void
setClearReferencesHttpClientKeepAliveThread(boolean
The new flag value
clearReferencesHttpClientKeepAliveThread
)

Set the clearReferencesHttpClientKeepAliveThread feature for this Context.

public void
setClearReferencesLogFactoryRelease(boolean
The new flag value
clearReferencesLogFactoryRelease
)

Set the clearReferencesLogFactoryRelease feature for this Context.

public void
setClearReferencesObjectStreamClassCaches(boolean clearReferencesObjectStreamClassCaches)

public void
setClearReferencesRmiTargets(boolean clearReferencesRmiTargets)

public void
setClearReferencesStopThreads(boolean
The new flag value
clearReferencesStopThreads
)

Set the clearReferencesStopThreads feature for this Context.

public void
setClearReferencesStopTimerThreads(boolean
The new flag value
clearReferencesStopTimerThreads
)

Set the clearReferencesStopTimerThreads feature for this Context.

public void
setClearReferencesThreadLocals(boolean clearReferencesThreadLocals)

public void
setDelegate(boolean
The new "delegate first" flag
delegate
)

Set the "delegate first" flag for this class loader.

protected void
public void
setResources(WebResourceRoot
the resources from which the classloader will load the classes
resources
)

Set associated resources.

public void
setSkipMemoryLeakChecksOnJvmShutdown(boolean skipMemoryLeakChecksOnJvmShutdown)

public void
start()

Implements org.apache.catalina.Lifecycle.start.

Start the class loader.

public void
stop()

Implements org.apache.catalina.Lifecycle.stop.

Stop the class loader.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
Inherited from java.net.URLClassLoader:
closedefinePackagenewInstancenewInstance