Class MultipleParentClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- net.bytebuddy.dynamic.loading.InjectionClassLoader
-
- net.bytebuddy.dynamic.loading.MultipleParentClassLoader
-
public class MultipleParentClassLoader extends InjectionClassLoader
This
ClassLoader
is capable of loading classes from multiple parents. This class loader implicitly defines the bootstrap class loader to be its direct parent as it is required for all class loaders. This can be useful when creating a type that inherits a super type and interfaces that are defined by different, non-compatible class loaders.Note: Instances of this class loader can have the same class loader as its parent multiple times, either directly or indirectly by multiple parents sharing a common parent class loader. By definition, this implies that the bootstrap class loader is
#(direct parents) + 1
times a parent of this class loader. For theClassLoader.getResources(java.lang.String)
method, this means that this class loader might return the same url multiple times by representing the same class loader multiple times.Important: This class loader does not support the location of packages from its multiple parents. This breaks package equality when loading classes by either loading them directly via this class loader (e.g. by subclassing) or by loading classes with child class loaders of this class loader.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MultipleParentClassLoader.Builder
A builder to collect class loader and that creates aMultipleParentClassLoader
only if multiple or noClassLoader
s are found in the process.protected static class
MultipleParentClassLoader.CompoundEnumeration
A compound URL enumeration.-
Nested classes/interfaces inherited from class net.bytebuddy.dynamic.loading.InjectionClassLoader
InjectionClassLoader.Strategy
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<? extends java.lang.ClassLoader>
parents
The parents of this class loader in their application order.
-
Constructor Summary
Constructors Constructor Description MultipleParentClassLoader(java.lang.ClassLoader parent, java.util.List<? extends java.lang.ClassLoader> parents)
Creates a new class loader with multiple parents.MultipleParentClassLoader(java.lang.ClassLoader parent, java.util.List<? extends java.lang.ClassLoader> parents, boolean sealed)
Creates a new class loader with multiple parents.MultipleParentClassLoader(java.util.List<? extends java.lang.ClassLoader> parents)
Creates a new class loader with multiple parents.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<java.lang.String,java.lang.Class<?>>
doDefineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions)
Defines a group of types to be loaded by this class loader.java.net.URL
getResource(java.lang.String name)
java.util.Enumeration<java.net.URL>
getResources(java.lang.String name)
protected java.lang.Class<?>
loadClass(java.lang.String name, boolean resolve)
-
Methods inherited from class net.bytebuddy.dynamic.loading.InjectionClassLoader
defineClass, defineClasses, isSealed
-
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, getResourceAsStream, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
MultipleParentClassLoader
public MultipleParentClassLoader(java.util.List<? extends java.lang.ClassLoader> parents)
Creates a new class loader with multiple parents.- Parameters:
parents
- The parents of this class loader in their application order. This list must not containnull
, i.e. the bootstrap class loader which is an implicit parent of any class loader.
-
MultipleParentClassLoader
public MultipleParentClassLoader(java.lang.ClassLoader parent, java.util.List<? extends java.lang.ClassLoader> parents)
Creates a new class loader with multiple parents.- Parameters:
parent
- An explicit parent in compliance with the class loader API. This explicit parent should only be set if the current platform does not allow creating a class loader that extends the bootstrap loader.parents
- The parents of this class loader in their application order. This list must not containnull
, i.e. the bootstrap class loader which is an implicit parent of any class loader.
-
MultipleParentClassLoader
public MultipleParentClassLoader(java.lang.ClassLoader parent, java.util.List<? extends java.lang.ClassLoader> parents, boolean sealed)
Creates a new class loader with multiple parents.- Parameters:
parent
- An explicit parent in compliance with the class loader API. This explicit parent should only be set if the current platform does not allow creating a class loader that extends the bootstrap loader.parents
- The parents of this class loader in their application order. This list must not containnull
, i.e. the bootstrap class loader which is an implicit parent of any class loader.sealed
-true
if the class loader is sealed for injection of additional classes.
-
-
Method Detail
-
loadClass
protected java.lang.Class<?> loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
- Overrides:
loadClass
in classjava.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
-
getResource
public java.net.URL getResource(java.lang.String name)
- Overrides:
getResource
in classjava.lang.ClassLoader
-
getResources
public java.util.Enumeration<java.net.URL> getResources(java.lang.String name) throws java.io.IOException
- Overrides:
getResources
in classjava.lang.ClassLoader
- Throws:
java.io.IOException
-
doDefineClasses
protected java.util.Map<java.lang.String,java.lang.Class<?>> doDefineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions)
Description copied from class:InjectionClassLoader
Defines a group of types to be loaded by this class loader.- Specified by:
doDefineClasses
in classInjectionClassLoader
- Parameters:
typeDefinitions
- The types binary representations.- Returns:
- The mapping of defined classes or previously defined classes by their name.
-
-