Package net.bytebuddy.agent.builder
Class ResettableClassFileTransformer.WithDelegation.Substitutable
java.lang.Object
net.bytebuddy.agent.builder.ResettableClassFileTransformer.AbstractBase
net.bytebuddy.agent.builder.ResettableClassFileTransformer.WithDelegation.Substitutable
- All Implemented Interfaces:
ClassFileTransformer
,ResettableClassFileTransformer
,ResettableClassFileTransformer.Substitutable
- Enclosing class:
ResettableClassFileTransformer.WithDelegation
@Enhance
protected static class ResettableClassFileTransformer.WithDelegation.Substitutable
extends ResettableClassFileTransformer.AbstractBase
implements ResettableClassFileTransformer.Substitutable
A standard implementation of a substitutable
ResettableClassFileTransformer
.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interface
A factory for creating a subclass ofResettableClassFileTransformer.WithDelegation.Substitutable
that supports the module system, if available.Nested classes/interfaces inherited from interface net.bytebuddy.agent.builder.ResettableClassFileTransformer
ResettableClassFileTransformer.AbstractBase, ResettableClassFileTransformer.Substitutable, ResettableClassFileTransformer.WithDelegation
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ResettableClassFileTransformer
The class file transformer to delegate to.private static final ResettableClassFileTransformer.WithDelegation.Substitutable.Factory
A dispatcher for invoking the correct transformer method. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Substitutable
(ResettableClassFileTransformer classFileTransformer) Creates a new delegating resettable class file transformer. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> T
doPrivileged
(PrivilegedAction<T> action) A proxy forjava.security.AccessController#doPrivileged
that is activated if available.iterator
(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, Class<?> classBeingRedefined, ProtectionDomain protectionDomain) Creates an iterator over the transformers that are applied for a given type.of
(ResettableClassFileTransformer classFileTransformer) Creates a new substitutable class file transformer of another class file transformer.boolean
reset
(Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RedefinitionStrategy redefinitionStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener) Deregisters this class file transformer and redefines any transformed class to its state without this class file transformer applied, if the supplied redefinition strategy is enabled.void
substitute
(ResettableClassFileTransformer classFileTransformer) Substitutes the current class file transformer.byte[]
transform
(ClassLoader classLoader, String internalName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] binaryRepresentation) unwrap()
Returns the underlying non-substitutable class file transformer.Methods inherited from class net.bytebuddy.agent.builder.ResettableClassFileTransformer.AbstractBase
reset, reset, reset, reset, reset, reset, reset
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.instrument.ClassFileTransformer
transform
-
Field Details
-
DISPATCHER
A dispatcher for invoking the correct transformer method. -
classFileTransformer
The class file transformer to delegate to.
-
-
Constructor Details
-
Substitutable
Creates a new delegating resettable class file transformer.- Parameters:
classFileTransformer
- The class file transformer to delegate to.
-
-
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.
-
of
public static ResettableClassFileTransformer.Substitutable of(ResettableClassFileTransformer classFileTransformer) Creates a new substitutable class file transformer of another class file transformer.- Parameters:
classFileTransformer
- The class file transformer to wrap.- Returns:
- A substitutable version of the supplied class file transformer.
-
substitute
Substitutes the current class file transformer.- Specified by:
substitute
in interfaceResettableClassFileTransformer.Substitutable
- Parameters:
classFileTransformer
- The class file transformer to use.
-
unwrap
Returns the underlying non-substitutable class file transformer.- Specified by:
unwrap
in interfaceResettableClassFileTransformer.Substitutable
- Returns:
- The underlying non-substitutable class file transformer.
-
iterator
public Iterator<AgentBuilder.Transformer> iterator(TypeDescription typeDescription, @MaybeNull ClassLoader classLoader, @MaybeNull JavaModule module, @MaybeNull Class<?> classBeingRedefined, @MaybeNull ProtectionDomain protectionDomain) Creates an iterator over the transformers that are applied for a given type.- Specified by:
iterator
in interfaceResettableClassFileTransformer
- Parameters:
typeDescription
- A description of a type.classLoader
- The type's class loader ornull
if the boot loader.module
- The type's module ornull
if the module system is not supported by the current VM.classBeingRedefined
- The class being redefined ornull
if the type is not yet loaded.protectionDomain
- The type's protection domain ornull
if not available.- Returns:
- An iterator over the transformers that are applied by this class file transformer if the given type is discovered.
-
reset
public boolean reset(Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RedefinitionStrategy redefinitionStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener) Deregisters this class file transformer and redefines any transformed class to its state without this class file transformer applied, if the supplied redefinition strategy is enabled. If it is not enabled, only the
AgentBuilder.InstallationListener
is informed about the resetting without undoing any code changes.Note: A reset class file transformer should not be reinstalled. Instead, the
AgentBuilder
which built the transformer should be asked to install a new transformer.Important: Most JVMs do not support changes of a class's structure after a class was already loaded. Therefore, it is typically required that this class file transformer was built while enabling
AgentBuilder.disableClassFormatChanges()
.- Specified by:
reset
in interfaceResettableClassFileTransformer
- Parameters:
instrumentation
- The instrumentation instance from which to deregister the transformer.classFileTransformer
- The actual class file transformer to deregister which might bethis
instance or any wrapper.redefinitionStrategy
- The redefinition to apply.redefinitionDiscoveryStrategy
- The discovery strategy for the types to reset.redefinitionBatchAllocator
- The batch allocator to use.redefinitionListener
- The redefinition listener to apply.- Returns:
true
if a reset was applied and this transformer was not previously removed.
-
transform
public byte[] transform(ClassLoader classLoader, String internalName, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] binaryRepresentation) throws IllegalClassFormatException - Specified by:
transform
in interfaceClassFileTransformer
- Throws:
IllegalClassFormatException
-