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
@Enhance public static class ClassInjector.UsingReflection extends ClassInjector.AbstractBase
A class injector that uses reflective method calls.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceClassInjector.UsingReflection.DispatcherA dispatcher for accessing aClassLoaderreflectively.protected static interfaceClassInjector.UsingReflection.SystemA 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
Fields Modifier and Type Field Description private static java.lang.reflect.MethodCHECK_PERMISSIONThejava.lang.SecurityManager#checkPermissionmethod ornullif not available.private java.lang.ClassLoaderclassLoaderThe class loader into which the classes are to be injected.private static ClassInjector.UsingReflection.Dispatcher.InitializableDISPATCHERThe dispatcher to use for accessing a class loader via reflection.private booleanforbidExistingDetermines if an exception should be thrown when attempting to load a type that already exists.private PackageDefinitionStrategypackageDefinitionStrategyThe package definer to be queried for package definitions.private java.security.ProtectionDomainprotectionDomainThe protection domain that is used when loading classes.private static ClassInjector.UsingReflection.SystemSYSTEMA proxy forjava.lang.Systemto access the security manager if available.-
Fields inherited from interface net.bytebuddy.dynamic.loading.ClassInjector
ALLOW_EXISTING_TYPES, SUPPRESS_ACCESS_CHECKS
-
-
Constructor Summary
Constructors Constructor Description UsingReflection(java.lang.ClassLoader classLoader)Creates a new injector for the givenClassLoaderand a defaultProtectionDomainand a trivialPackageDefinitionStrategywhich does not trigger an error when discovering existent classes.UsingReflection(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain)Creates a new injector for the givenClassLoaderand a defaultPackageDefinitionStrategywhere the injection of existent classes does not trigger an error.UsingReflection(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain, PackageDefinitionStrategy packageDefinitionStrategy, boolean forbidExisting)Creates a new injector for the givenClassLoaderandProtectionDomain.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> TdoPrivileged(java.security.PrivilegedAction<T> action)A proxy forjava.security.AccessController#doPrivilegedthat is activated if available.java.util.Map<java.lang.String,java.lang.Class<?>>injectRaw(java.util.Map<? extends java.lang.String,byte[]> types)Injects the given types into the represented class loader using a mapping from name to binary representation.booleanisAlive()Indicates if this class injector is available on the current VM.static booleanisAvailable()Indicates if this class injection is available on the current VM.static ClassInjectorofSystemClassLoader()Creates a class injector for the system class loader.-
Methods inherited from class net.bytebuddy.dynamic.loading.ClassInjector.AbstractBase
inject
-
-
-
-
Field Detail
-
DISPATCHER
private static final ClassInjector.UsingReflection.Dispatcher.Initializable DISPATCHER
The dispatcher to use for accessing a class loader via reflection.
-
SYSTEM
private static final ClassInjector.UsingReflection.System SYSTEM
A proxy forjava.lang.Systemto access the security manager if available.
-
CHECK_PERMISSION
private static final java.lang.reflect.Method CHECK_PERMISSION
Thejava.lang.SecurityManager#checkPermissionmethod ornullif not available.
-
classLoader
private final java.lang.ClassLoader classLoader
The class loader into which the classes are to be injected.
-
protectionDomain
@MaybeNull @ValueHandling(REVERSE_NULLABILITY) private final java.security.ProtectionDomain protectionDomain
The protection domain that is used when loading classes.
-
packageDefinitionStrategy
private final PackageDefinitionStrategy packageDefinitionStrategy
The package definer to be queried for package definitions.
-
forbidExisting
private final boolean forbidExisting
Determines if an exception should be thrown when attempting to load a type that already exists.
-
-
Constructor Detail
-
UsingReflection
public UsingReflection(java.lang.ClassLoader classLoader)
Creates a new injector for the givenClassLoaderand a defaultProtectionDomainand a trivialPackageDefinitionStrategywhich does not trigger an error when discovering existent classes.- Parameters:
classLoader- TheClassLoaderinto which new class definitions are to be injected. Must not be the bootstrap loader.
-
UsingReflection
public UsingReflection(java.lang.ClassLoader classLoader, @MaybeNull java.security.ProtectionDomain protectionDomain)Creates a new injector for the givenClassLoaderand a defaultPackageDefinitionStrategywhere the injection of existent classes does not trigger an error.- Parameters:
classLoader- TheClassLoaderinto 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(java.lang.ClassLoader classLoader, @MaybeNull java.security.ProtectionDomain protectionDomain, PackageDefinitionStrategy packageDefinitionStrategy, boolean forbidExisting)Creates a new injector for the givenClassLoaderandProtectionDomain.- Parameters:
classLoader- TheClassLoaderinto 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 Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivilegedthat 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:
trueif this injector is available on the current VM.
-
injectRaw
public java.util.Map<java.lang.String,java.lang.Class<?>> injectRaw(java.util.Map<? extends java.lang.String,byte[]> types)
Injects the given types into the represented class loader using a mapping from name to binary representation.- Parameters:
types- The types to load via injection.- 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:
trueif this class injection is available.
-
ofSystemClassLoader
public static ClassInjector ofSystemClassLoader()
Creates a class injector for the system class loader.- Returns:
- A class injector for the system class loader.
-
-