Top Description Fields Constructors Methods
io.github.classgraph

public Class ClassGraphClassLoader

extends ClassLoader
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.URL, .URLClassLoader, java.security.ProtectionDomain, java.util.Arrays, .Collections, .Enumeration, .LinkedHashSet, .List, .Set, nonapi.io.github.classgraph.scanspec.ScanSpec, nonapi.io.github.classgraph.utils.JarUtils, .VersionFinder, .VersionFinder.OperatingSystem

ClassLoader for classes found by ClassGraph during scanning.

Field Summary

Modifier and TypeField and Description
private Set<ClassLoader>
addedClassLoaderDelegationOrder

The ordered set of overridden or added classloaders to try delegating to.

private final ClassLoader
classpathClassLoader

A URLClassLoader consisting of URLs on the classpath.

private Set<ClassLoader>
environmentClassLoaderDelegationOrder

The ordered set of environment classloaders to try delegating to.

private final boolean
initializeLoadedClasses

Whether or not to initialize loaded classes.

private List<ClassLoader>
overrideClassLoaders

Any override classloader(s).

private final ScanResult
scanResult

The scan result.

Constructor Summary

AccessConstructor and Description
pack-priv
ClassGraphClassLoader(final ScanResult
The ScanResult.
scanResult
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
protected Class<?>
findClass(final String
The binary name of the class
className
)

Overrides java.lang.ClassLoader.findClass.

Finds the class with the specified binary name.

public URL
getResource(final String
The resource name
path
)

Overrides java.lang.ClassLoader.getResource.

Finds the resource with the given name.

public InputStream
getResourceAsStream(final String
The resource name
path
)

Overrides java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.

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

Overrides java.lang.ClassLoader.getResources.

Finds all the resources with the given name.

public URL[]

Returns:

The classpath URLs in the ScanResult handled by this ClassLoader.
getURLs
()

Get classpath URLs.

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

addedClassLoaderDelegationOrderback to summary
private Set<ClassLoader> addedClassLoaderDelegationOrder

The ordered set of overridden or added classloaders to try delegating to.

classpathClassLoaderback to summary
private final ClassLoader classpathClassLoader

A URLClassLoader consisting of URLs on the classpath.

environmentClassLoaderDelegationOrderback to summary
private Set<ClassLoader> environmentClassLoaderDelegationOrder

The ordered set of environment classloaders to try delegating to.

initializeLoadedClassesback to summary
private final boolean initializeLoadedClasses

Whether or not to initialize loaded classes.

overrideClassLoadersback to summary
private List<ClassLoader> overrideClassLoaders

Any override classloader(s).

scanResultback to summary
private final ScanResult scanResult

The scan result.

Constructor Detail

ClassGraphClassLoaderback to summary
pack-priv ClassGraphClassLoader(final ScanResult scanResult)

Constructor.

Parameters
scanResult:ScanResult

The ScanResult.

Method Detail

findClassback to summary
protected Class<?> findClass(final String className) throws ClassNotFoundException, LinkageError, SecurityException

Overrides java.lang.ClassLoader.findClass.

Doc from java.lang.ClassLoader.findClass.

Finds the class with the specified binary name. This method should be overridden by class loader implementations that follow the delegation model for loading classes, and will be invoked by the loadClass method after checking the parent class loader for the requested class.

Parameters
className:String

The binary name of the class

Returns:Class<?>

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:
If the class could not be found
getResourceback to summary
public URL getResource(final String path)

Overrides java.lang.ClassLoader.getResource.

Doc from java.lang.ClassLoader.getResource.

Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a '/'-separated path name that identifies the resource.

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

Parameters
path:String

The resource name

Returns:URL

URL object for reading the resource; null if the resource could not be found, a URL could not be constructed to locate the resource, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

Annotations
@Override
getResourceAsStreamback to summary
public InputStream getResourceAsStream(final String path)

Overrides java.lang.ClassLoader.getResourceAsStream.

Doc from java.lang.ClassLoader.getResourceAsStream.

Returns an input stream for reading the specified resource.

The search order is described in the documentation for getResource(String).

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally.

Parameters
path:String

The resource name

Returns:InputStream

An input stream for reading the resource; null if the resource could not be found, the resource is in a package that is not opened unconditionally, or access to the resource is denied by the security manager.

Annotations
@Override
getResourcesback to summary
public Enumeration<URL> getResources(final String path) throws IOException

Overrides java.lang.ClassLoader.getResources.

Doc from java.lang.ClassLoader.getResources.

Finds all the resources with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

The name of a resource is a /-separated path name that identifies the resource.

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with ".class", this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

Parameters
path:String

The resource name

Returns:Enumeration<URL>

An enumeration of URL objects for the resource. If no resources could be found, the enumeration will be empty. Resources for which a URL cannot be constructed, are in a package that is not opened unconditionally, or access to the resource is denied by the security manager, are not returned in the enumeration.

Annotations
@Override
Exceptions
IOException:
If I/O errors occur
getURLsback to summary
public URL[] getURLs()

Get classpath URLs.

Returns:URL[]

The classpath URLs in the ScanResult handled by this ClassLoader.