Top Description Inners Fields Constructors Methods
org.easymock.bytebuddy.dynamic.loading

public abstract Class InjectionClassLoader

extends ClassLoader
Class Inheritance
Known Direct Subclasses
org.easymock.bytebuddy.dynamic.loading.MultipleParentClassLoader, org.easymock.bytebuddy.dynamic.loading.ByteArrayClassLoader
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, org.easymock.bytebuddy.description.type.TypeDescription, org.easymock.bytebuddy.utility.nullability.MaybeNull, java.lang.reflect.Method, java.util.Collections, .HashMap, .LinkedHashMap, .Map, java.util.concurrent.atomic.AtomicBoolean

An injection class loader allows for the injection of a class after the class loader was created. Injection is only possible if this class loader is not sealed.

Important Note

Not sealing a class loader allows to break package encapsulation for anybody getting hold of a reference to this class loader.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
InjectionClassLoader.Strategy

A class loading strategy for adding a type to an injection class loader.

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
sealed

Indicates if this class loader is sealed, i.e. forbids runtime injection.

Constructor Summary

AccessConstructor and Description
protected
InjectionClassLoader(ClassLoader
The class loader's parent.
parent
,
boolean
Indicates if this class loader is sealed, i.e. forbids runtime injection.
sealed
)

Creates a new injection class loader.

Method Summary

Modifier and TypeMethod and Description
public Class<?>

Returns:

The defined class or a previously defined class.
defineClass
(String
The name of the type.
name
,
byte[]
The type's binary representation.
binaryRepresentation
)

Defines a new type to be loaded by this class loader.

public Map<String, Class<?>>

Returns:

The mapping of defined classes or previously defined classes by their name.
defineClasses
(Map<String, byte[]>
The types binary representations.
typeDefinitions
)

Defines a group of types to be loaded by this class loader.

protected abstract Map<String, Class<?>>

Returns:

The mapping of defined classes or previously defined classes by their name.
doDefineClasses
(Map<String, byte[]>
The types binary representations.
typeDefinitions
)

Defines a group of types to be loaded by this class loader.

private static void
doRegisterAsParallelCapable()

Registers class loader as parallel capable if possible.

public boolean

Returns:

true if this class loader is sealed.
isSealed
()

Returns true if this class loader is sealed.

public boolean

Returns:

true if the class loader was not sealed previously.
seal
()

Seals the class loader and returns true if the class loader was not sealed previously.

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

sealedback to summary
private final AtomicBoolean sealed

Indicates if this class loader is sealed, i.e. forbids runtime injection.

Constructor Detail

InjectionClassLoaderback to summary
protected InjectionClassLoader(ClassLoader parent, boolean sealed)

Creates a new injection class loader.

Parameters
parent:ClassLoader

The class loader's parent.

sealed:boolean

Indicates if this class loader is sealed, i.e. forbids runtime injection.

Method Detail

defineClassback to summary
public Class<?> defineClass(String name, byte[] binaryRepresentation) throws ClassNotFoundException

Defines a new type to be loaded by this class loader.

Parameters
name:String

The name of the type.

binaryRepresentation:byte[]

The type's binary representation.

Returns:Class<?>

The defined class or a previously defined class.

Exceptions
ClassNotFoundException:
If the class could not be loaded.
defineClassesback to summary
public Map<String, Class<?>> defineClasses(Map<String, byte[]> typeDefinitions) throws ClassNotFoundException

Defines a group of types to be loaded by this class loader. If this class loader is sealed, an IllegalStateException is thrown.

Parameters
typeDefinitions:Map<String, byte[]>

The types binary representations.

Returns:Map<String, Class<?>>

The mapping of defined classes or previously defined classes by their name.

Exceptions
ClassNotFoundException:
If the class could not be loaded.
doDefineClassesback to summary
protected abstract Map<String, Class<?>> doDefineClasses(Map<String, byte[]> typeDefinitions) throws ClassNotFoundException

Defines a group of types to be loaded by this class loader.

Parameters
typeDefinitions:Map<String, byte[]>

The types binary representations.

Returns:Map<String, Class<?>>

The mapping of defined classes or previously defined classes by their name.

Exceptions
ClassNotFoundException:
If the class could not be loaded.
doRegisterAsParallelCapableback to summary
private static void doRegisterAsParallelCapable()

Registers class loader as parallel capable if possible.

Annotations
@SuppressFBWarnings:DP_DO_INSIDE_DO_PRIVILEGED
justification:Must be invoked from targeting class loader type.
isSealedback to summary
public boolean isSealed()

Returns true if this class loader is sealed.

Returns:boolean

true if this class loader is sealed.

sealback to summary
public boolean seal()

Seals the class loader and returns true if the class loader was not sealed previously.

Returns:boolean

true if the class loader was not sealed previously.

org.easymock.bytebuddy.dynamic.loading back to summary

public final Enum InjectionClassLoader.Strategy

extends Enum<InjectionClassLoader.Strategy>
implements ClassLoadingStrategy<InjectionClassLoader>
Class Inheritance
All Implemented Interfaces
org.easymock.bytebuddy.dynamic.loading.ClassLoadingStrategy

A class loading strategy for adding a type to an injection class loader.

Field Summary

Modifier and TypeField and Description
public static final InjectionClassLoader.Strategy
INSTANCE

The singleton instance.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Map<TypeDescription, Class<?>>
load(InjectionClassLoader
The class loader to used for loading the classes.
classLoader
,
Map<TypeDescription, byte[]>
Byte array representations of the types to be loaded mapped by their descriptions, where an iteration order defines an order in which they are supposed to be loaded, if relevant.
types
)

Implements org.easymock.bytebuddy.dynamic.loading.ClassLoadingStrategy.load.

Loads a given collection of classes given their binary representation.
public static InjectionClassLoader.Strategy
public static InjectionClassLoader.Strategy[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

INSTANCEback to summary
public static final InjectionClassLoader.Strategy INSTANCE

The singleton instance.

Constructor Detail

Strategyback to summary
private Strategy()

Method Detail

loadback to summary
public Map<TypeDescription, Class<?>> load(InjectionClassLoader classLoader, Map<TypeDescription, byte[]> types)

Implements org.easymock.bytebuddy.dynamic.loading.ClassLoadingStrategy.load.

Doc from org.easymock.bytebuddy.dynamic.loading.ClassLoadingStrategy.load.

Loads a given collection of classes given their binary representation.

Parameters
classLoader:InjectionClassLoader

The class loader to used for loading the classes.

types:Map<TypeDescription, byte[]>

Byte array representations of the types to be loaded mapped by their descriptions, where an iteration order defines an order in which they are supposed to be loaded, if relevant.

Returns:Map<TypeDescription, Class<?>>

A collection of the loaded classes which will be initialized in the iteration order of the returned collection.

valueOfback to summary
public static InjectionClassLoader.Strategy valueOf(String name)
valuesback to summary
public static InjectionClassLoader.Strategy[] values()