Package net.bytebuddy.dynamic.loading
Class ClassInjector.UsingUnsafe.Factory
java.lang.Object
net.bytebuddy.dynamic.loading.ClassInjector.UsingUnsafe.Factory
- Enclosing class:
ClassInjector.UsingUnsafe
A factory for creating a
ClassInjector
that uses sun.misc.Unsafe
if available but attempts a fallback
to using jdk.internal.misc.Unsafe
if the jdk.internal
module is not resolved or unavailable.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An access resolver that invokesAccessibleObject.setAccessible(boolean)
totrue
in a given privilege scope. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClassInjector.UsingUnsafe.Dispatcher.Initializable
The dispatcher to use. -
Constructor Summary
ConstructorsModifierConstructorDescriptionFactory()
Creates a new factory for an unsafe class injector that uses Byte Buddy's privileges to accessingjdk.internal.misc.Unsafe
if available.protected
Creates a new factory.Factory
(ClassInjector.UsingUnsafe.Factory.AccessResolver accessResolver) Creates a new factory for an unsafe class injector. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if this factory creates a valid dispatcher.make
(ClassLoader classLoader) Creates a new class injector for the given class loader without aProtectionDomain
.make
(ClassLoader classLoader, ProtectionDomain protectionDomain) Creates a new class injector for the given class loader and protection domain.resolve
(Instrumentation instrumentation) Resolves an injection strategy that uses unsafe injection if available and also attempts to open and usejdk.internal.misc.Unsafe
as a fallback.resolve
(Instrumentation instrumentation, boolean local) Resolves an injection strategy that uses unsafe injection if available and also attempts to open and usejdk.internal.misc.Unsafe
as a fallback.
-
Field Details
-
dispatcher
The dispatcher to use.
-
-
Constructor Details
-
Factory
public Factory()Creates a new factory for an unsafe class injector that uses Byte Buddy's privileges to accessingjdk.internal.misc.Unsafe
if available. -
Factory
Creates a new factory for an unsafe class injector.- Parameters:
accessResolver
- The access resolver to use.
-
Factory
Creates a new factory.- Parameters:
dispatcher
- The dispatcher to use.
-
-
Method Details
-
resolve
Resolves an injection strategy that uses unsafe injection if available and also attempts to open and usejdk.internal.misc.Unsafe
as 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(Instrumentation instrumentation, boolean local) Resolves an injection strategy that uses unsafe injection if available and also attempts to open and usejdk.internal.misc.Unsafe
as a fallback.- Parameters:
instrumentation
- The instrumentation instance to use for opening the internal package if required.local
-false
if a new class should in a separated class loader and module should be created for opening thejdk.internal.misc
package. 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()Returnstrue
if this factory creates a valid dispatcher.- Returns:
true
if this factory creates a valid dispatcher.
-
make
Creates a new class injector for the given class loader without aProtectionDomain
.- Parameters:
classLoader
- The class loader to inject into ornull
to inject into the bootstrap loader.- Returns:
- An appropriate class injector.
-
make
public ClassInjector make(@MaybeNull ClassLoader classLoader, @MaybeNull ProtectionDomain protectionDomain) Creates a new class injector for the given class loader and protection domain.- Parameters:
classLoader
- The class loader to inject into ornull
to inject into the bootstrap loader.protectionDomain
- The protection domain to apply ornull
if no protection domain should be used.- Returns:
- An appropriate class injector.
-