Top Description Inners Fields Constructors Methods
net.bytebuddy

public Class ByteBuddy

extends Object
Class Inheritance
Annotations
@Enhance
Imports
net.bytebuddy.build.AccessControllerPlugin, .HashCodeAndEqualsPlugin, net.bytebuddy.description.annotation.AnnotationDescription, .AnnotationValue, net.bytebuddy.description.field.FieldDescription, net.bytebuddy.description.method.MethodDescription, .ParameterDescription, net.bytebuddy.description.modifier.*, net.bytebuddy.description.type.*, net.bytebuddy.dynamic.*, net.bytebuddy.dynamic.scaffold.*, net.bytebuddy.dynamic.scaffold.inline.DecoratingDynamicTypeBuilder, .MethodNameTransformer, .RebaseDynamicTypeBuilder, .RedefinitionDynamicTypeBuilder, net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy, .SubclassDynamicTypeBuilder, net.bytebuddy.implementation.Implementation, .MethodCall, .SuperMethodCall, net.bytebuddy.implementation.attribute.AnnotationRetention, .AnnotationValueFilter, .MethodAttributeAppender, 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.IntegerConstant, .TextConstant, net.bytebuddy.implementation.bytecode.member.FieldAccess, .MethodInvocation, .MethodReturn, .MethodVariableAccess, net.bytebuddy.matcher.ElementMatcher, .LatentMatcher, net.bytebuddy.utility.*, net.bytebuddy.utility.nullability.MaybeNull, net.bytebuddy.utility.privilege.GetSystemPropertyAction, net.bytebuddy.jar.asm.MethodVisitor, .Opcodes, java.lang.annotation.Annotation, .ElementType, java.lang.reflect.Type, java.security.PrivilegedAction, java.util.*

Instances of this class serve as a focus point for configuration of the library's behavior and as an entry point to any form of code generation using the library. For this purpose, Byte Buddy offers a fluent API which allows for the step-wise generation of a new Java type. A type is generated either by: Byte Buddy's API does not change when a type is rebased, redefined or subclassed. All types are created via the net.bytebuddy.dynamic.DynamicType.Builder interface. Byte Buddy's API is expressed by fully immutable components and is therefore thread-safe. As a consequence, method calls must be chained for all of Byte Buddy's component, e.g. a method call like the following has no effect:
ByteBuddy byteBuddy = new ByteBuddy();
byteBuddy.foo()
Instead, the following method chain is correct use of the API:
ByteBuddy byteBuddy = new ByteBuddy().foo();

For the creation of Java agents, Byte Buddy offers a convenience API implemented by the net.bytebuddy.agent.builder.AgentBuilder. The API wraps a ByteBuddy instance and offers agent-specific configuration opportunities by integrating against the java.lang.instrument.Instrumentation API.

See Also
net.bytebuddy.agent.builder.AgentBuilder

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
ByteBuddy.EnumerationImplementation

An implementation fo the values method of an enumeration type.

protected static enum
ByteBuddy.RecordConstructorStrategy

A constructor strategy for implementing a Java record.

protected static enum
ByteBuddy.RecordObjectMethod

Implements the object methods of the Java record type.

Field Summary

Modifier and TypeField and Description
protected final AnnotationRetention
annotationRetention

The annotation retention strategy to use.

protected final AnnotationValueFilter.Factory
annotationValueFilterFactory

The annotation value filter factory to use.

protected final AuxiliaryType.NamingStrategy
auxiliaryTypeNamingStrategy

The naming strategy to use for naming auxiliary types.

private static final String
BYTE_BUDDY_DEFAULT_CONTEXT_NAME

The default name of a fixed context name for synthetic fields and methods.

private static final String
BYTE_BUDDY_DEFAULT_PREFIX

The default prefix for the default net.bytebuddy.NamingStrategy.

private static final String
BYTE_BUDDY_DEFAULT_SUFFIX

The default suffix when defining a AuxiliaryType.NamingStrategy.

protected final ClassFileVersion
classFileVersion

The class file version to use for types that are not based on an existing class file.

protected final ClassWriterStrategy
classWriterStrategy

The class writer strategy to use.

private static final AuxiliaryType.NamingStrategy
DEFAULT_AUXILIARY_NAMING_STRATEGY

The default auxiliary naming strategy or null if no such strategy is set.

private static final Implementation.Context.Factory
DEFAULT_IMPLEMENTATION_CONTEXT_FACTORY

The default implementation context factory or null if no such factory is set.

public static final String
DEFAULT_NAMING_PROPERTY

A property that controls the default naming strategy.

private static final NamingStrategy
DEFAULT_NAMING_STRATEGY

The default naming strategy or null if no such strategy is set.

protected final LatentMatcher<? super MethodDescription>
ignoredMethods

A matcher for identifying methods that should be excluded from instrumentation.

protected final Implementation.Context.Factory
implementationContextFactory

The implementation context factory to use.

protected final InstrumentedType.Factory
instrumentedTypeFactory

The instrumented type factory to use.

protected final MethodGraph.Compiler
methodGraphCompiler

The method graph compiler to use.

protected final NamingStrategy
namingStrategy

The naming strategy to use.

protected final TypeValidation
typeValidation

Determines if a type should be explicitly validated.

protected final VisibilityBridgeStrategy
visibilityBridgeStrategy

The visibility bridge strategy to apply.

Constructor Summary

AccessConstructor and Description
public
ByteBuddy()

Creates a new Byte Buddy instance with a default configuration that is suitable for most use cases.

public
ByteBuddy(ClassFileVersion
The class file version to use for types that are not based on an existing class file.
classFileVersion
)

Creates a new Byte Buddy instance with a default configuration that is suitable for most use cases.

protected
ByteBuddy(ClassFileVersion
The class file version to use for types that are not based on an existing class file.
classFileVersion
,
NamingStrategy
The naming strategy to use.
namingStrategy
,
AuxiliaryType.NamingStrategy
The naming strategy to use for naming auxiliary types.
auxiliaryTypeNamingStrategy
,
AnnotationValueFilter.Factory
The annotation value filter factory to use.
annotationValueFilterFactory
,
AnnotationRetention
The annotation retention strategy to use.
annotationRetention
,
Implementation.Context.Factory
The implementation context factory to use.
implementationContextFactory
,
MethodGraph.Compiler
The method graph compiler to use.
methodGraphCompiler
,
InstrumentedType.Factory
The instrumented type factory to use.
instrumentedTypeFactory
,
TypeValidation
Determines if a type should be explicitly validated.
typeValidation
,
VisibilityBridgeStrategy
The visibility bridge strategy to apply.
visibilityBridgeStrategy
,
ClassWriterStrategy
The class writer strategy to use.
classWriterStrategy
,
LatentMatcher<? super MethodDescription>
A matcher for identifying methods that should be excluded from instrumentation.
ignoredMethods
)

Creates a new Byte Buddy instance.

Method Summary

Modifier and TypeMethod and Description
public <
The loaded type of the decorated type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for decorating the provided type.
decorate
(Class<T>
The type to decorate.
type
)

Decorates a type with net.bytebuddy.asm.AsmVisitorWrapper and allows adding attributes and annotations.

public <
The loaded type of the decorated type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for decorating the provided type.
decorate
(Class<T>
The type to decorate.
type
,
ClassFileLocator
The class file locator to use.
classFileLocator
)

Decorates a type with net.bytebuddy.asm.AsmVisitorWrapper and allows adding attributes and annotations.

public <
The loaded type of the decorated type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for decorating the provided type.
decorate
(TypeDescription
The type to decorate.
type
,
ClassFileLocator
The class file locator to use.
classFileLocator
)

Decorates a type with net.bytebuddy.asm.AsmVisitorWrapper and allows adding attributes and annotations.

private static <
The type of the action's resolved value.
T
>
T

Returns:

The action's resolved value.
doPrivileged
(PrivilegedAction<T>
The action to execute from a privileged context.
action
)

A proxy for java.security.AccessController#doPrivileged that is activated if available.

public ByteBuddy

Returns:

A new Byte Buddy instance that excludes any method from instrumentation if it is matched by the supplied matcher.
ignore
(ElementMatcher<? super MethodDescription>
A matcher for identifying methods to be excluded from instrumentation.
ignoredMethods
)

Creates a new configuration where any MethodDescription that matches the provided method matcher is excluded from instrumentation.

public ByteBuddy

Returns:

A new Byte Buddy instance that excludes any method from instrumentation if it is matched by the supplied matcher.
ignore
(LatentMatcher<? super MethodDescription>
A matcher for identifying methods to be excluded from instrumentation.
ignoredMethods
)

Creates a new configuration where any MethodDescription that matches the provided method matcher is excluded from instrumentation.

public DynamicType.Builder<? extends Annotation>

Returns:

A type builder that creates a new Annotation type.
makeAnnotation
()

Creates a new Annotation type.

public DynamicType.Builder<? extends Enum<?>>

Returns:

A type builder for creating an enumeration type.
makeEnumeration
(String...
The names of the type's enumeration constants
value
)

Creates a new Enum type.

public DynamicType.Builder<? extends Enum<?>>

Returns:

A type builder for creating an enumeration type.
makeEnumeration
(Collection<? extends String>
The names of the type's enumeration constants
values
)

Creates a new Enum type.

public DynamicType.Builder<?>

Returns:

A type builder that creates a new interface type.
makeInterface
()

Creates a new, plain interface type.

public <
A loaded type that the generated interface is guaranteed to inherit.
T
>
DynamicType.Builder<T>

Returns:

A type builder that creates a new interface type.
makeInterface
(Class<T>
An interface type that the generated interface implements.
interfaceType
)

Creates a new interface type that extends the provided interface.

public DynamicType.Builder<?>

Returns:

A type builder that creates a new interface type.
makeInterface
(Type...
The interface types to implement. The types must be raw or parameterized types. All type variables that are referenced by a parameterized type must be declared by the generated subclass before creating the type.
interfaceType
)

Creates a new interface type that extends the provided interface.

public DynamicType.Builder<?>

Returns:

A type builder that creates a new interface type.
makeInterface
(List<? extends Type>
The interface types to implement. The types must be raw or parameterized types. All type variables that are referenced by a parameterized type must be declared by the generated subclass before creating the type.
interfaceTypes
)

Creates a new interface type that extends the provided interface.

public DynamicType.Builder<?>

Returns:

A type builder that creates a new interface type.
makeInterface
(TypeDefinition...
The interface types to implement. The types must be raw or parameterized types. All type variables that are referenced by a parameterized type must be declared by the generated subclass before creating the type.
interfaceType
)

Creates a new interface type that extends the provided interface.

public DynamicType.Builder<?>

Returns:

A type builder that creates a new interface type.
makeInterface
(Collection<? extends TypeDefinition>
The interface types to implement. The types must be raw or parameterized types. All type variables that are referenced by a parameterized type must be declared by the generated subclass before creating the type.
interfaceTypes
)

Creates a new interface type that extends the provided interface.

public DynamicType.Builder<?>

Returns:

A type builder that creates a package-info class file.
makePackage
(String
The fully qualified name of the package.
name
)

Creates a new package definition.

public DynamicType.Builder<?>

Returns:

A dynamic type builder that creates a record.
makeRecord
()

Creates a new Java record.

public <
The loaded type of the rebased type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for rebasing the provided type.
rebase
(Class<T>
The type that is being rebased.
type
)

Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type's class such that the class's original can be invoked from the new method implementations.

public <
The loaded type of the rebased type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for rebasing the provided type.
rebase
(Class<T>
The type that is being rebased.
type
,
ClassFileLocator
The class file locator that is queried for the rebased type's class file.
classFileLocator
)

Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type's class such that the class's original can be invoked from the new method implementations.

public <
The loaded type of the rebased type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for rebasing the provided type.
rebase
(Class<T>
The type that is being rebased.
type
,
ClassFileLocator
The class file locator that is queried for the rebased type's class file.
classFileLocator
,
MethodNameTransformer
The method name transformer for renaming a method that is rebased.
methodNameTransformer
)

Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type's class such that the class's original can be invoked from the new method implementations.

public <
The loaded type of the rebased type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for rebasing the provided type.
rebase
(TypeDescription
The type that is being rebased.
type
,
ClassFileLocator
The class file locator that is queried for the rebased type's class file.
classFileLocator
)

Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type's class such that the class's original can be invoked from the new method implementations.

public <
The loaded type of the rebased type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for rebasing the provided type.
rebase
(TypeDescription
The type that is being rebased.
type
,
ClassFileLocator
The class file locator that is queried for the rebased type's class file.
classFileLocator
,
MethodNameTransformer
The method name transformer for renaming a method that is rebased.
methodNameTransformer
)

Rebases the given type where any intercepted method that is declared by the redefined type is preserved within the rebased type's class such that the class's original can be invoked from the new method implementations.

public DynamicType.Builder<?>

Returns:

A type builder for rebasing the given package.
rebase
(Package
The package that is being rebased.
aPackage
,
ClassFileLocator
The class file locator to use for locating the package's class file.
classFileLocator
)

Rebases a package.

public DynamicType.Builder<?>

Returns:

A type builder for rebasing the given package.
rebase
(PackageDescription
The package that is being rebased.
aPackage
,
ClassFileLocator
The class file locator to use for locating the package's class file.
classFileLocator
)

Rebases a package.

public <
The loaded type of the redefined type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for redefining the provided type.
redefine
(Class<T>
The type that is being redefined.
type
)

Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced by the new implementation.

public <
The loaded type of the redefined type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for redefining the provided type.
redefine
(Class<T>
The type that is being redefined.
type
,
ClassFileLocator
The class file locator that is queried for the redefined type's class file.
classFileLocator
)

Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced by the new implementation.

public <
The loaded type of the redefined type.
T
>
DynamicType.Builder<T>

Returns:

A type builder for redefining the provided type.
redefine
(TypeDescription
The type that is being redefined.
type
,
ClassFileLocator
The class file locator that is queried for the redefined type's class file.
classFileLocator
)

Redefines the given type where any intercepted method that is declared by the redefined type is fully replaced by the new implementation.

public <
A loaded type that the generated class is guaranteed to inherit.
T
>
DynamicType.Builder<T>

Returns:

A type builder for creating a new class extending the provided class or interface.
subclass
(Class<T>
The super class or interface type to extend.
superType
)

Creates a new builder for subclassing the provided type.

public <
A loaded type that the generated class is guaranteed to inherit.
T
>
DynamicType.Builder<T>

Returns:

A type builder for creating a new class extending the provided class or interface.
subclass
(Class<T>
The super class or interface type to extend.
superType
,
ConstructorStrategy
A constructor strategy that determines the
constructorStrategy
)

Creates a new builder for subclassing the provided type.

public DynamicType.Builder<?>

Returns:

A type builder for creating a new class extending the provided class or interface.
subclass
(Type
The super class or interface type to extend. The type must be a raw type or parameterized type. All type variables that are referenced by the generic type must be declared by the generated subclass before creating the type.
superType
)

Creates a new builder for subclassing the provided type.

public DynamicType.Builder<?>

Returns:

A type builder for creating a new class extending the provided class or interface.
subclass
(Type
The super class or interface type to extend. The type must be a raw type or parameterized type. All type variables that are referenced by the generic type must be declared by the generated subclass before creating the type.
superType
,
ConstructorStrategy
A constructor strategy that determines the
constructorStrategy
)

Creates a new builder for subclassing the provided type.

public DynamicType.Builder<?>

Returns:

A type builder for creating a new class extending the provided class or interface.
subclass
(TypeDefinition
The super class or interface type to extend. The type must be a raw type or parameterized type. All type variables that are referenced by the generic type must be declared by the generated subclass before creating the type.
superType
)

Creates a new builder for subclassing the provided type.

public DynamicType.Builder<?>

Returns:

A type builder for creating a new class extending the provided class or interface.
subclass
(TypeDefinition
The super class or interface type to extend. The type must be a raw type or parameterized type. All type variables that are referenced by the generic type must be declared by the generated subclass before creating the type.
superType
,
ConstructorStrategy
A constructor strategy that determines the
constructorStrategy
)

Creates a new builder for subclassing the provided type.

public ByteBuddy

Returns:

A new Byte Buddy instance that uses the supplied class file version.
with
(ClassFileVersion
The class file version to use for types that are not based on an existing class file.
classFileVersion
)

Creates a new configuration where all class files that are not based on an existing class file are created using the supplied class file version.

public ByteBuddy

Returns:

A new Byte Buddy instance that uses the supplied naming strategy.
with
(NamingStrategy
The naming strategy to apply when creating a new dynamic type.
namingStrategy
)

Creates a new configuration where new types are named by applying the given naming strategy.

public ByteBuddy

Returns:

A new Byte Buddy instance that uses the supplied naming strategy for auxiliary types.
with
(AuxiliaryType.NamingStrategy
The naming strategy to apply when creating a new auxiliary type.
auxiliaryTypeNamingStrategy
)

Creates a new configuration where auxiliary types are named by applying the given naming strategy.

public ByteBuddy

Returns:

A new Byte Buddy instance that uses the supplied annotation value filter factory.
with
(AnnotationValueFilter.Factory
The annotation value filter factory to use.
annotationValueFilterFactory
)

Creates a new configuration where annotation values are written according to the given filter factory.

public ByteBuddy

Returns:

A new Byte Buddy instance that uses the supplied annotation retention strategy.
with
(AnnotationRetention
The annotation retention strategy to use.
annotationRetention
)

Creates a new configuration where annotations that are found in an existing class file are or are not preserved in the format they are discovered, i.e. rewritten in the format they were already present in the class file.

public ByteBuddy

Returns:

A new Byte Buddy instance that uses the supplied implementation context factory.
with
(Implementation.Context.Factory
The implementation context factory to use for defining an instrumented type.
implementationContextFactory
)

Creates a new configuration where the net.bytebuddy.implementation.Implementation.Context of any created type is a product of the given implementation context factory.

public ByteBuddy

Returns:

A new Byte Buddy instance that uses the supplied method graph compiler.
with
(MethodGraph.Compiler
The method graph compiler to use for analyzing the instrumented type.
methodGraphCompiler
)

Creates a new configuration where the MethodGraph.Compiler is used for creating a MethodGraph of the instrumented type.

public ByteBuddy

Returns:

A new Byte Buddy instance that uses the supplied factory for creating instrumented types.
with
(InstrumentedType.Factory
The factory to use when creating instrumented types.
instrumentedTypeFactory
)

Configures Byte Buddy to use the specified factory for creating InstrumentedTypes.

public ByteBuddy

Returns:

A new Byte Buddy instance that applies the supplied type validation.
with
(TypeValidation
The type validation to apply during type creation.
typeValidation
)

Creates a new configuration that applies the supplied type validation.

public ByteBuddy

Returns:

A new Byte Buddy instance that applies the supplied visibility bridge strategy.
with
(VisibilityBridgeStrategy
The visibility bridge strategy to apply.
visibilityBridgeStrategy
)

Creates a new configuration that applies the supplied visibility bridge strategy.

public ByteBuddy

Returns:

A new Byte Buddy instance that applies the supplied class writer strategy.
with
(ClassWriterStrategy
The class writer strategy to apply during type creation.
classWriterStrategy
)

Creates a new configuration that applies the supplied class writer strategy.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait