Class ExistenceCheckingClassLoader
ClassLoader
that verifies the existence of a .class
resource before attempting
to load the class. Intended to sit in front of servlet container loaders we do not control.
This implementation overrides loadClass(String, boolean)
and uses ClassLoader.getResource(String)
to check whether the corresponding .class
file is available in
the classpath. If the resource is not found, a ClassNotFoundException
is thrown
immediately.
Parallel-capable parent loaders retain a per-class-name lock object for every load attempt,
including misses. By checking getResource(name + ".class") first and throwing ClassNotFoundException
on absence, we avoid calling loadClass
on misses, thus preventing
the parent from populating its lock map for nonexistent classes.
This class is only needed in PluginManager.UberClassLoader
. It is unnecessary
for plugin ClassLoader
s (because URLClassLoader2
mitigates lock retention via
ClassLoader.getClassLoadingLock(java.lang.String)
) and redundant for delegators (because DelegatingClassLoader
already avoids base locking).
- Author:
- Dmytro Ukhlov
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
Constructor Details
-
ExistenceCheckingClassLoader
-
ExistenceCheckingClassLoader
-
-
Method Details
-
loadClass
Short-circuits misses by checking for the.class
resource prior to delegation. Successful loads behave exactly as the parent would; misses do not touch the parent's per-name lock map.- Overrides:
loadClass
in classDelegatingClassLoader
- Parameters:
name
- The binary name of the classresolve
- Iftrue
then resolve the class- Returns:
- The resulting
Class
object - Throws:
ClassNotFoundException
- If the class could not be found
-