Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingUnsafe.Factory
- java.lang.Object
-
- net.bytebuddy.dynamic.loading.ClassInjector.UsingUnsafe.Factory
-
- Enclosing class:
- ClassInjector.UsingUnsafe
@Enhance public static class ClassInjector.UsingUnsafe.Factory extends java.lang.Object
A factory for creating aClassInjectorthat usessun.misc.Unsafeif available but attempts a fallback to usingjdk.internal.misc.Unsafeif thejdk.internalmodule is not resolved or unavailable.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceClassInjector.UsingUnsafe.Factory.AccessResolverAn access resolver that invokesAccessibleObject.setAccessible(boolean)totruein a given privilege scope.
-
Field Summary
Fields Modifier and Type Field Description private ClassInjector.UsingUnsafe.Dispatcher.InitializabledispatcherThe dispatcher to use.
-
Constructor Summary
Constructors Modifier Constructor Description Factory()Creates a new factory for an unsafe class injector that uses Byte Buddy's privileges to accessingjdk.internal.misc.Unsafeif available.protectedFactory(ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher)Creates a new factory.Factory(ClassInjector.UsingUnsafe.Factory.AccessResolver accessResolver)Creates a new factory for an unsafe class injector.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisAvailable()Returnstrueif this factory creates a valid dispatcher.ClassInjectormake(java.lang.ClassLoader classLoader)Creates a new class injector for the given class loader without aProtectionDomain.ClassInjectormake(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain)Creates a new class injector for the given class loader and protection domain.static ClassInjector.UsingUnsafe.Factoryresolve(java.lang.instrument.Instrumentation instrumentation)Resolves an injection strategy that uses unsafe injection if available and also attempts to open and usejdk.internal.misc.Unsafeas a fallback.static ClassInjector.UsingUnsafe.Factoryresolve(java.lang.instrument.Instrumentation instrumentation, boolean local)Resolves an injection strategy that uses unsafe injection if available and also attempts to open and usejdk.internal.misc.Unsafeas a fallback.
-
-
-
Field Detail
-
dispatcher
private final ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher
The dispatcher to use.
-
-
Constructor Detail
-
Factory
public Factory()
Creates a new factory for an unsafe class injector that uses Byte Buddy's privileges to accessingjdk.internal.misc.Unsafeif available.
-
Factory
public Factory(ClassInjector.UsingUnsafe.Factory.AccessResolver accessResolver)
Creates a new factory for an unsafe class injector.- Parameters:
accessResolver- The access resolver to use.
-
Factory
protected Factory(ClassInjector.UsingUnsafe.Dispatcher.Initializable dispatcher)
Creates a new factory.- Parameters:
dispatcher- The dispatcher to use.
-
-
Method Detail
-
resolve
public static ClassInjector.UsingUnsafe.Factory resolve(java.lang.instrument.Instrumentation instrumentation)
Resolves an injection strategy that uses unsafe injection if available and also attempts to open and usejdk.internal.misc.Unsafeas a fallback. This method generates a new class and module for opening the internal package to avoid its exposure to any non-trusted code.- Parameters:
instrumentation- The instrumentation instance to use for opening the internal package if required.- Returns:
- An appropriate injection strategy.
-
resolve
public static ClassInjector.UsingUnsafe.Factory resolve(java.lang.instrument.Instrumentation instrumentation, boolean local)
Resolves an injection strategy that uses unsafe injection if available and also attempts to open and usejdk.internal.misc.Unsafeas a fallback.- Parameters:
instrumentation- The instrumentation instance to use for opening the internal package if required.local-falseif a new class should in a separated class loader and module should be created for opening thejdk.internal.miscpackage. This way, the internal package is not exposed to any other classes within this class's module.- Returns:
- An appropriate injection strategy.
-
isAvailable
public boolean isAvailable()
Returnstrueif this factory creates a valid dispatcher.- Returns:
trueif this factory creates a valid dispatcher.
-
make
public ClassInjector make(java.lang.ClassLoader classLoader)
Creates a new class injector for the given class loader without aProtectionDomain.- Parameters:
classLoader- The class loader to inject into ornullto inject into the bootstrap loader.- Returns:
- An appropriate class injector.
-
make
public ClassInjector make(java.lang.ClassLoader classLoader, java.security.ProtectionDomain protectionDomain)
Creates a new class injector for the given class loader and protection domain.- Parameters:
classLoader- The class loader to inject into ornullto inject into the bootstrap loader.protectionDomain- The protection domain to apply ornullif no protection domain should be used.- Returns:
- An appropriate class injector.
-
-