Top Description Inners Methods
net.bytebuddy.agent.builder

public Interface AgentBuilder

Known Direct Subinterfaces
net.bytebuddy.agent.builder.AgentBuilder.Ignored, net.bytebuddy.agent.builder.AgentBuilder.RedefinitionListenable, net.bytebuddy.agent.builder.AgentBuilder.RedefinitionListenable.WithResubmissionSpecification, net.bytebuddy.agent.builder.AgentBuilder.Identified.Extendable
Known Direct Implementers
net.bytebuddy.agent.builder.AgentBuilder.Default, net.bytebuddy.agent.builder.AgentBuilder.Default.Delegator
Annotations
@SuppressWarnings:overloads
Imports
edu.umd.cs.findbugs.annotations.SuppressFBWarnings, net.bytebuddy.ByteBuddy, .ClassFileVersion, .NamingStrategy, net.bytebuddy.asm.Advice, .AsmVisitorWrapper, net.bytebuddy.build.AccessControllerPlugin, .EntryPoint, .HashCodeAndEqualsPlugin, .Plugin, net.bytebuddy.description.field.FieldDescription, net.bytebuddy.description.method.MethodDescription, .ParameterDescription, net.bytebuddy.description.modifier.FieldManifestation, .MethodManifestation, .Ownership, .TypeManifestation, .Visibility, net.bytebuddy.description.type.PackageDescription, .TypeDescription, net.bytebuddy.dynamic.ClassFileLocator, .DynamicType, .NexusAccessor, .TypeResolutionStrategy, .VisibilityBridgeStrategy, net.bytebuddy.dynamic.loading.ClassInjector, .ClassLoadingStrategy, .ClassReloadingStrategy, net.bytebuddy.dynamic.scaffold.InstrumentedType, .TypeValidation, net.bytebuddy.dynamic.scaffold.inline.MethodNameTransformer, net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy, net.bytebuddy.implementation.ExceptionMethod, .Implementation, .LoadedTypeInitializer, .MethodCall, net.bytebuddy.implementation.auxiliary.AuxiliaryType, net.bytebuddy.implementation.bytecode.ByteCodeAppender, .Duplication, .StackManipulation, .TypeCreation, net.bytebuddy.implementation.bytecode.assign.Assigner, .TypeCasting, net.bytebuddy.implementation.bytecode.collection.ArrayFactory, net.bytebuddy.implementation.bytecode.constant.ClassConstant, .IntegerConstant, .TextConstant, net.bytebuddy.implementation.bytecode.member.FieldAccess, .MethodInvocation, .MethodReturn, .MethodVariableAccess, net.bytebuddy.matcher.ElementMatcher, .ElementMatchers, .LatentMatcher, net.bytebuddy.pool.TypePool, net.bytebuddy.utility.CompoundList, .JavaConstant, .JavaModule, .JavaType, net.bytebuddy.utility.dispatcher.JavaDispatcher, net.bytebuddy.utility.nullability.AlwaysNull, .MaybeNull, net.bytebuddy.jar.asm.ConstantDynamic, .Handle, .Label, .MethodVisitor, .Opcodes, .Type, java.io.File, .NotSerializableException, .ObjectInputStream, .ObjectOutputStream, .PrintStream, .Serializable, java.lang.instrument.ClassDefinition, .ClassFileTransformer, .IllegalClassFormatException, .Instrumentation, .UnmodifiableClassException, java.lang.ref.WeakReference, java.lang.reflect.Constructor, .InvocationTargetException, java.net.URL, .URLClassLoader, java.security.PrivilegedAction, .ProtectionDomain, java.util.AbstractSet, .ArrayList, .Arrays, .Collection, .Collections, .HashMap, .HashSet, .Iterator, .LinkedHashMap, .LinkedHashSet, .List, .Map, .NoSuchElementException, .Random, .Set, java.util.concurrent.Callable, .ConcurrentHashMap, .ConcurrentMap, .ExecutionException, .ExecutorService, .Executors, .Future, .ScheduledExecutorService, .TimeUnit, java.util.concurrent.atomic.AtomicBoolean, .AtomicInteger, java.util.concurrent.locks.Lock, .ReentrantLock

An agent builder provides a convenience API for defining a Java agent. By default, this transformation is applied by rebasing the type if not specified otherwise by setting a TypeStrategy.

When defining several net.bytebuddy.agent.builder.AgentBuilder.Transformers, the agent builder always applies the transformers that were supplied with the last applicable matcher. Therefore, more general transformers should be defined first.

Note

Any transformation is performed using the java.security.AccessControlContext of an agent's creator.

Important Note

Types that implement lambda expressions (functional interfaces) are not instrumented by default but only when enabling the builder's LambdaInstrumentationStrategy.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
AgentBuilder.CircularityLock

A circularity lock is responsible for preventing that a ClassFileLocator is used recursively.

public static interface
AgentBuilder.ClassFileBufferStrategy

This strategy determines how the provided class file buffer is used.

public static class
public static interface
AgentBuilder.DescriptionStrategy

A description strategy is responsible for resolving a TypeDescription when transforming or retransforming/-defining a type.

public static interface
AgentBuilder.FallbackStrategy

A fallback strategy allows to reattempt a transformation or a consideration for redefinition/retransformation in case an exception occurs.

public static interface
AgentBuilder.Identified

Describes an net.bytebuddy.agent.builder.AgentBuilder which was handed a matcher for identifying types to instrumented in order to supply one or several net.bytebuddy.agent.builder.AgentBuilder.Transformers.

public static interface
AgentBuilder.Ignored

Allows to further specify ignored types.

public static interface
AgentBuilder.InitializationStrategy

An initialization strategy which determines the handling of net.bytebuddy.implementation.LoadedTypeInitializers and the loading of auxiliary types.

public static interface
AgentBuilder.InjectionStrategy

A strategy for injecting auxiliary types into a class loader.

public static interface
AgentBuilder.InstallationListener

A listener that is notified during the installation and the resetting of a class file transformer.

public static enum
AgentBuilder.LambdaInstrumentationStrategy

Implements the instrumentation of the LambdaMetafactory if this feature is enabled.

public static interface
AgentBuilder.Listener

A listener that is informed about events that occur during an instrumentation process.

public static interface
AgentBuilder.LocationStrategy

A strategy for creating a ClassFileLocator when instrumenting a type.

public static interface
AgentBuilder.Matchable<
The type that is produced by chaining a matcher.
T extends AgentBuilder.Matchable<T>
>

An abstraction for extending a matcher.

public static enum
AgentBuilder.PatchMode

Determines how patching a ResettableClassFileTransformer resolves the transformer exchange.

public static interface
AgentBuilder.PoolStrategy

A type locator allows to specify how TypeDescriptions are resolved by an net.bytebuddy.agent.builder.AgentBuilder.

public static interface
AgentBuilder.RawMatcher

A matcher that allows to determine if a net.bytebuddy.agent.builder.AgentBuilder.Transformer should be applied during the execution of a java.lang.instrument.ClassFileTransformer that was generated by an net.bytebuddy.agent.builder.AgentBuilder.

public static interface
AgentBuilder.RedefinitionListenable

An agent builder configuration that allows the registration of listeners to the redefinition process.

public static enum
AgentBuilder.RedefinitionStrategy

A redefinition strategy regulates how already loaded classes are modified by a built agent.

public static interface
AgentBuilder.Transformer

A transformer allows to apply modifications to a net.bytebuddy.dynamic.DynamicType.

public static interface
AgentBuilder.TransformerDecorator

A decorator that allows to change the class file transformer that is registered.

public static interface
AgentBuilder.TypeStrategy

A type strategy is responsible for creating a type builder for a type that is being instrumented.

Method Summary

Modifier and TypeMethod and Description
public AgentBuilder

Returns:

A new instance of this agent builder that assures the supplied types module visibility.
assureReadEdgeFromAndTo
(Instrumentation
The instrumentation instance that is used for adding a module read-dependency.
instrumentation
,
Class<?>...
The types for which to assure their module-visibility from and to any instrumented class.
type
)

Assures that all modules of the supplied types are read by the module of any instrumented type and vice versa.

public AgentBuilder

Returns:

A new instance of this agent builder that assures the supplied types module visibility.
assureReadEdgeFromAndTo
(Instrumentation
The instrumentation instance that is used for adding a module read-dependency.
instrumentation
,
JavaModule...
The modules for which to assure their module-visibility from and to any instrumented class.
module
)

Assures that all supplied modules are read by the module of any instrumented type and vice versa.

public AgentBuilder

Returns:

A new instance of this agent builder that assures the supplied types module visibility.
assureReadEdgeFromAndTo
(Instrumentation
The instrumentation instance that is used for adding a module read-dependency.
instrumentation
,
Collection<? extends JavaModule>
The modules for which to assure their module-visibility from and to any instrumented class.
modules
)

Assures that all supplied modules are read by the module of any instrumented type and vice versa.

public AgentBuilder

Returns:

A new instance of this agent builder that assures the supplied types module visibility.
assureReadEdgeTo
(Instrumentation
The instrumentation instance that is used for adding a module read-dependency.
instrumentation
,
Class<?>...
The types for which to assure their module-visibility from any instrumented class.
type
)

Assures that all modules of the supplied types are read by the module of any instrumented type.

public AgentBuilder

Returns:

A new instance of this agent builder that assures the supplied types module visibility.
assureReadEdgeTo
(Instrumentation
The instrumentation instance that is used for adding a module read-dependency.
instrumentation
,
JavaModule...
The modules for which to assure their module-visibility from any instrumented class.
module
)

Assures that all supplied modules are read by the module of any instrumented type.

public AgentBuilder

Returns:

A new instance of this agent builder that assures the supplied types module visibility.
assureReadEdgeTo
(Instrumentation
The instrumentation instance that is used for adding a module read-dependency.
instrumentation
,
Collection<? extends JavaModule>
The modules for which to assure their module-visibility from any instrumented class.
modules
)

Assures that all supplied modules are read by the module of any instrumented type.

public AgentBuilder

Returns:

A new instance of this agent builder that does not apply any implicit changes to the received class file.
disableClassFormatChanges
()

Disables all implicit changes on a class file that Byte Buddy would apply for certain instrumentations.

public AgentBuilder

Returns:

A new instance of this agent builder which does not use a native method prefix.
disableNativeMethodPrefix
()

Disables the use of a native method prefix for instrumented methods.

public AgentBuilder

Returns:

A new instance of this agent builder which uses the given native method prefix.
enableNativeMethodPrefix
(String
The prefix to be used.
prefix
)

Enables the use of the given native method prefix for instrumented methods.

public AgentBuilder.Ignored

Returns:

A new instance of this agent builder that ignores all types that are matched by the provided matcher. All previous matchers for ignored types are discarded.
ignore
(ElementMatcher<? super TypeDescription>
A matcher that identifies types that should not be instrumented.
typeMatcher
)

Excludes any type that is matched by the provided matcher from instrumentation and considers types by all ClassLoaders.

public AgentBuilder.Ignored

Returns:

A new instance of this agent builder that ignores all types that are matched by the provided matcher. All previous matchers for ignored types are discarded.
ignore
(ElementMatcher<? super TypeDescription>
A matcher that identifies types that should not be instrumented.
typeMatcher
,
ElementMatcher<? super ClassLoader>
A matcher that identifies a class loader that identifies classes that should not be instrumented.
classLoaderMatcher
)

Excludes any type that is matched by the provided matcher and is loaded by a class loader matching the second matcher.

public AgentBuilder.Ignored

Returns:

A new instance of this agent builder that ignores all types that are matched by the provided matcher. All previous matchers for ignored types are discarded.
ignore
(ElementMatcher<? super TypeDescription>
A matcher that identifies types that should not be instrumented.
typeMatcher
,
ElementMatcher<? super ClassLoader>
A matcher that identifies a class loader that identifies classes that should not be instrumented.
classLoaderMatcher
,
ElementMatcher<? super JavaModule>
A matcher that identifies a module that identifies classes that should not be instrumented. On a JVM that does not support the Java modules system, this matcher is not applied.
moduleMatcher
)

Excludes any type that is matched by the provided matcher and is loaded by a class loader matching the second matcher.

public AgentBuilder.Ignored

Returns:

A new instance of this agent builder that ignores all types that are matched by the provided matcher. All previous matchers for ignored types are discarded.
ignore
(AgentBuilder.RawMatcher
A raw matcher that identifies types that should not be instrumented.
rawMatcher
)

Excludes any type that is matched by the raw matcher provided to this method.

public ResettableClassFileTransformer

Returns:

The installed class file transformer.
installOn
(Instrumentation
The instrumentation on which this agent builder's configuration is to be installed.
instrumentation
)

Creates and installs a ResettableClassFileTransformer that implements the configuration of this agent builder with a given java.lang.instrument.Instrumentation.

public ResettableClassFileTransformer

Returns:

The installed class file transformer.
installOnByteBuddyAgent
()

Creates and installs a ResettableClassFileTransformer that implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method.

public ClassFileTransformer

Returns:

A class file transformer that implements the configuration of this agent builder.
makeRaw
()

Creates a ResettableClassFileTransformer that implements the configuration of this agent builder.

public ResettableClassFileTransformer

Returns:

The installed class file transformer.
patchOn
(Instrumentation
The instrumentation on which this agent builder's configuration is to be installed.
instrumentation
,
ResettableClassFileTransformer
The class file transformer that is being patched.
classFileTransformer
)

Creates and installs a ResettableClassFileTransformer that implements the configuration of this agent builder with a given java.lang.instrument.Instrumentation.

public ResettableClassFileTransformer

Returns:

The installed class file transformer.
patchOn
(Instrumentation
The instrumentation on which this agent builder's configuration is to be installed.
instrumentation
,
ResettableClassFileTransformer
The class file transformer that is being patched.
classFileTransformer
,
AgentBuilder.RawMatcher
The differential matcher to decide what types need retransformation.
differentialMatcher
)

Creates and installs a ResettableClassFileTransformer that implements the configuration of this agent builder with a given java.lang.instrument.Instrumentation.

public ResettableClassFileTransformer

Returns:

The installed class file transformer.
patchOn
(Instrumentation
The instrumentation on which this agent builder's configuration is to be installed.
instrumentation
,
ResettableClassFileTransformer
The class file transformer that is being patched.
classFileTransformer
,
AgentBuilder.PatchMode
The patch mode to apply.
patchMode
)

Creates and installs a ResettableClassFileTransformer that implements the configuration of this agent builder with a given java.lang.instrument.Instrumentation.

public ResettableClassFileTransformer

Returns:

The installed class file transformer.
patchOn
(Instrumentation
The instrumentation on which this agent builder's configuration is to be installed.
instrumentation
,
ResettableClassFileTransformer
The class file transformer that is being patched.
classFileTransformer
,
AgentBuilder.RawMatcher
The differential matcher to decide what types need retransformation.
differentialMatcher
,
AgentBuilder.PatchMode
The patch mode to apply.
patchMode
)

Creates and installs a ResettableClassFileTransformer that implements the configuration of this agent builder with a given java.lang.instrument.Instrumentation.

public ResettableClassFileTransformer

Returns:

The installed class file transformer.
patchOnByteBuddyAgent
(ResettableClassFileTransformer
The class file transformer that is being patched.
classFileTransformer
)

Creates and installs a ResettableClassFileTransformer that implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method.

public ResettableClassFileTransformer

Returns:

The installed class file transformer.
patchOnByteBuddyAgent
(ResettableClassFileTransformer
The class file transformer that is being patched.
classFileTransformer
,
AgentBuilder.PatchMode
The patch mode to apply.
patchMode
)

Creates and installs a ResettableClassFileTransformer that implements the configuration of this agent builder with the Byte Buddy-agent which must be installed prior to calling this method.

public AgentBuilder.Identified.Narrowable

Returns:

A definable that represents this agent builder which allows for the definition of one or several net.bytebuddy.agent.builder.AgentBuilder.Transformers to be applied when the given typeMatcher indicates a match.
type
(ElementMatcher<? super TypeDescription>
An net.bytebuddy.matcher.ElementMatcher that is applied on the type being loaded that decides if the entailed net.bytebuddy.agent.builder.AgentBuilder.Transformers should be applied for that type.
typeMatcher
)

Matches a type being loaded in order to apply the supplied net.bytebuddy.agent.builder.AgentBuilder.Transformers before loading this type.

public AgentBuilder.Identified.Narrowable

Returns:

A definable that represents this agent builder which allows for the definition of one or several net.bytebuddy.agent.builder.AgentBuilder.Transformers to be applied when both the given typeMatcher and classLoaderMatcher indicate a match.
type
(ElementMatcher<? super TypeDescription>
An net.bytebuddy.matcher.ElementMatcher that is applied on the type being loaded that decides if the entailed net.bytebuddy.agent.builder.AgentBuilder.Transformers should be applied for that type.
typeMatcher
,
ElementMatcher<? super ClassLoader>
An net.bytebuddy.matcher.ElementMatcher that is applied to the java.lang.ClassLoader that is loading the type being loaded. This matcher is always applied first where the type matcher is not applied in case that this matcher does not indicate a match.
classLoaderMatcher
)

Matches a type being loaded in order to apply the supplied net.bytebuddy.agent.builder.AgentBuilder.Transformers before loading this type.

public AgentBuilder.Identified.Narrowable

Returns:

A definable that represents this agent builder which allows for the definition of one or several net.bytebuddy.agent.builder.AgentBuilder.Transformers to be applied when both the given typeMatcher and classLoaderMatcher indicate a match.
type
(ElementMatcher<? super TypeDescription>
An net.bytebuddy.matcher.ElementMatcher that is applied on the type being loaded that decides if the entailed net.bytebuddy.agent.builder.AgentBuilder.Transformers should be applied for that type.
typeMatcher
,
ElementMatcher<? super ClassLoader>
An net.bytebuddy.matcher.ElementMatcher that is applied to the java.lang.ClassLoader that is loading the type being loaded. This matcher is always applied second where the type matcher is not applied in case that this matcher does not indicate a match.
classLoaderMatcher
,
ElementMatcher<? super JavaModule>
An net.bytebuddy.matcher.ElementMatcher that is applied to the JavaModule of the type being loaded. This matcher is always applied first where the class loader and type matchers are not applied in case that this matcher does not indicate a match. On a JVM that does not support the Java modules system, this matcher is not applied.
moduleMatcher
)

Matches a type being loaded in order to apply the supplied net.bytebuddy.agent.builder.AgentBuilder.Transformers before loading this type.

public AgentBuilder.Identified.Narrowable

Returns:

A definable that represents this agent builder which allows for the definition of one or several net.bytebuddy.agent.builder.AgentBuilder.Transformers to be applied when the given matcher indicates a match.
type
(AgentBuilder.RawMatcher
A matcher that decides if the entailed net.bytebuddy.agent.builder.AgentBuilder.Transformers should be applied for a type that is being loaded.
matcher
)

Matches a type being loaded in order to apply the supplied net.bytebuddy.agent.builder.AgentBuilder.Transformers before loading this type.

public AgentBuilder

Returns:

A new agent builder that considers the supplied classes in its warmup.
warmUp
(Class<?>...
The types to include in the warmup.
type
)

Warms up the generated ClassFileTransformer to trigger class loading of classes used by the transformer prior to its actual use.

public AgentBuilder

Returns:

A new agent builder that considers the supplied classes in its warmup.
warmUp
(Collection<Class<?>>
The types to include in the warmup.
types
)

Warms up the generated ClassFileTransformer to trigger class loading of classes used by the transformer prior to its actual use.

public AgentBuilder

Returns:

A new instance of this agent builder which makes use of the given byteBuddy instance.
with
(ByteBuddy
The Byte Buddy instance to be used.
byteBuddy
)

Defines the given net.bytebuddy.ByteBuddy instance to be used by the created agent.

public AgentBuilder

Returns:

A new instance of this agent builder which creates an agent that informs the given listener about events.
with
(AgentBuilder.Listener
The listener to be notified.
listener
)

Defines the given net.bytebuddy.agent.builder.AgentBuilder.Listener to be notified by the created agent.

public AgentBuilder

Returns:

A new instance of this agent builder which creates an agent that uses the supplied circularity lock.
with
(AgentBuilder.CircularityLock
The circularity lock to use.
circularityLock
)

Defines a circularity lock that is acquired upon executing code that potentially loads new classes.

public AgentBuilder

Returns:

A new instance of this agent builder which uses the given type locator for looking up class files.
with
(AgentBuilder.PoolStrategy
The type locator to use.
poolStrategy
)

Defines the use of the given type locator for locating a TypeDescription for an instrumented type.

public AgentBuilder

Returns:

A new instance of this agent builder which uses the given location strategy for looking up class files.
with
(AgentBuilder.LocationStrategy
The location strategy to use.
locationStrategy
)

Defines the use of the given location strategy for locating binary data to given class names.

public AgentBuilder

Returns:

A new instance of this agent builder which uses the given class file locator for global type lookup.
with
(ClassFileLocator
The class file locator to add.
classFileLocator
)

Registers an additional class file locator for types that are globally available but cannot be located otherwise.

public AgentBuilder

Returns:

A new instance of this agent builder which uses the given type strategy.
with
(AgentBuilder.TypeStrategy
The type strategy to use.
typeStrategy
)

Defines how types should be transformed, e.g. if they should be rebased or redefined by the created agent.

public AgentBuilder

Returns:

A new instance of this agent builder that applies the given initialization strategy.
with
(AgentBuilder.InitializationStrategy
The initialization strategy to use.
initializationStrategy
)

Defines a given initialization strategy to be applied to generated types.

public AgentBuilder.RedefinitionListenable.WithoutBatchStrategy

Returns:

A new instance of this agent builder that applies the given redefinition strategy.
with
(AgentBuilder.RedefinitionStrategy
The redefinition strategy to apply.
redefinitionStrategy
)

Specifies a strategy for modifying types that were already loaded prior to the installation of this transformer.

public AgentBuilder

Returns:

A new instance of this agent builder where this feature is explicitly enabled or disabled.
with
(AgentBuilder.LambdaInstrumentationStrategy
true if this feature should be enabled.
lambdaInstrumentationStrategy
)

Enables or disables management of the JVM's LambdaMetafactory which is responsible for creating classes that implement lambda expressions.

public AgentBuilder

Returns:

A new instance of this agent builder that applies the given description strategy.
with
(AgentBuilder.DescriptionStrategy
The description strategy to use.
descriptionStrategy
)

Specifies a strategy to be used for resolving TypeDescription for any type handled by the created transformer.

public AgentBuilder

Returns:

A new agent builder that applies the supplied fallback strategy.
with
(AgentBuilder.FallbackStrategy
The fallback strategy to be used.
fallbackStrategy
)

Specifies a fallback strategy to that this agent builder applies upon installing an agent and during class file transformation.

public AgentBuilder

Returns:

A new agent builder that applies the supplied class file buffer strategy.
with
(AgentBuilder.ClassFileBufferStrategy
The class file buffer strategy to use.
classFileBufferStrategy
)

Specifies a class file buffer strategy that determines the use of the buffer supplied to a class file transformer.

public AgentBuilder

Returns:

A new agent builder that applies the supplied installation listener.
with
(AgentBuilder.InstallationListener
The installation listener to register.
installationListener
)

Adds an installation listener that is notified during installation events.

public AgentBuilder

Returns:

A new agent builder with the supplied injection strategy configured.
with
(AgentBuilder.InjectionStrategy
The injection strategy to use.
injectionStrategy
)

Defines a strategy for injecting auxiliary types into the target class loader.

public AgentBuilder

Returns:

A new agent builder that applies the supplied transformer decorator.
with
(AgentBuilder.TransformerDecorator
A decorator to wrap the created class file transformer.
transformerDecorator
)

Adds a decorator for the created class file transformer.