Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingReflection
java.lang.Object
net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
net.bytebuddy.dynamic.loading.ClassInjector.UsingReflection
- All Implemented Interfaces:
ClassInjector
- Enclosing interface:
ClassInjector
A class injector that uses reflective method calls.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interface
A dispatcher for accessing aClassLoader
reflectively.protected static interface
A proxy ofjava.lang.System
.Nested classes/interfaces inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ClassInjector.AbstractBase, ClassInjector.UsingInstrumentation, ClassInjector.UsingJna, ClassInjector.UsingLookup, ClassInjector.UsingReflection, ClassInjector.UsingUnsafe
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Method
Thejava.lang.SecurityManager#checkPermission
method ornull
if not available.private final ClassLoader
The class loader into which the classes are to be injected.private static final ClassInjector.UsingReflection.Dispatcher.Initializable
The dispatcher to use for accessing a class loader via reflection.private final boolean
Determines if an exception should be thrown when attempting to load a type that already exists.private final PackageDefinitionStrategy
The package definer to be queried for package definitions.private final ProtectionDomain
The protection domain that is used when loading classes.private static final ClassInjector.UsingReflection.System
A proxy forjava.lang.System
to access the security manager if available.Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ALLOW_EXISTING_TYPES, SUPPRESS_ACCESS_CHECKS
-
Constructor Summary
ConstructorsConstructorDescriptionUsingReflection
(ClassLoader classLoader) Creates a new injector for the givenClassLoader
and a defaultProtectionDomain
and a trivialPackageDefinitionStrategy
which does not trigger an error when discovering existent classes.UsingReflection
(ClassLoader classLoader, ProtectionDomain protectionDomain) Creates a new injector for the givenClassLoader
and a defaultPackageDefinitionStrategy
where the injection of existent classes does not trigger an error.UsingReflection
(ClassLoader classLoader, ProtectionDomain protectionDomain, PackageDefinitionStrategy packageDefinitionStrategy, boolean forbidExisting) Creates a new injector for the givenClassLoader
andProtectionDomain
. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> T
doPrivileged
(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.injectRaw
(Set<String> names, ClassFileLocator classFileLocator) Injects the given types into the represented class loader.boolean
isAlive()
Indicates if this class injector is available on the current VM.static boolean
Indicates if this class injection is available on the current VM.static ClassInjector
Creates a class injector for the system class loader.Methods inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
inject, inject, injectRaw
-
Field Details
-
DISPATCHER
The dispatcher to use for accessing a class loader via reflection. -
SYSTEM
A proxy forjava.lang.System
to access the security manager if available. -
CHECK_PERMISSION
Thejava.lang.SecurityManager#checkPermission
method ornull
if not available. -
classLoader
The class loader into which the classes are to be injected. -
protectionDomain
The protection domain that is used when loading classes. -
packageDefinitionStrategy
The package definer to be queried for package definitions. -
forbidExisting
private final boolean forbidExistingDetermines if an exception should be thrown when attempting to load a type that already exists.
-
-
Constructor Details
-
UsingReflection
Creates a new injector for the givenClassLoader
and a defaultProtectionDomain
and a trivialPackageDefinitionStrategy
which does not trigger an error when discovering existent classes.- Parameters:
classLoader
- TheClassLoader
into which new class definitions are to be injected. Must not be the bootstrap loader.
-
UsingReflection
Creates a new injector for the givenClassLoader
and a defaultPackageDefinitionStrategy
where the injection of existent classes does not trigger an error.- Parameters:
classLoader
- TheClassLoader
into which new class definitions are to be injected. Must not be the bootstrap loader.protectionDomain
- The protection domain to apply during class definition.
-
UsingReflection
public UsingReflection(ClassLoader classLoader, @MaybeNull ProtectionDomain protectionDomain, PackageDefinitionStrategy packageDefinitionStrategy, boolean forbidExisting) Creates a new injector for the givenClassLoader
andProtectionDomain
.- Parameters:
classLoader
- TheClassLoader
into which new class definitions are to be injected.Must not be the bootstrap loader.protectionDomain
- The protection domain to apply during class definition.packageDefinitionStrategy
- The package definer to be queried for package definitions.forbidExisting
- Determines if an exception should be thrown when attempting to load a type that already exists.
-
-
Method Details
-
doPrivileged
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.- Type Parameters:
T
- The type of the action's resolved value.- Parameters:
action
- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
isAlive
public boolean isAlive()Indicates if this class injector is available on the current VM.- Returns:
true
if this injector is available on the current VM.
-
injectRaw
Injects the given types into the represented class loader.- Parameters:
names
- The names of the types to load via injection.classFileLocator
- The class file locator to use for resolving binary representations.- Returns:
- The loaded types that were passed as arguments.
-
isAvailable
public static boolean isAvailable()Indicates if this class injection is available on the current VM.- Returns:
true
if this class injection is available.
-
ofSystemClassLoader
Creates a class injector for the system class loader.- Returns:
- A class injector for the system class loader.
-