Byte Buddy is a runtime code generation and bytecode manipulation library for Java. It provides a fluent API for creating and modifying Java classes during execution, enabling developers to define class structures, methods, and fields programmatically without requiring a compiler or direct bytecode assembly.
The library supports agent-based class transformation, allowing loaded classes to be modified during JVM startup or runtime through a Java agent that intercepts class loading. It offers bytecode-level method interception for fine-grained control over method behavior, annotation-based code weaving for metadata injection, and automatic stack map frame computation required by the JVM verifier. Byte Buddy also includes a class file pool abstraction for efficient caching and reuse of bytecode across multiple transformations, along with dynamic class loading integration for loading generated classes into the JVM.
Beyond its core identity as a bytecode manipulation tool, Byte Buddy enables runtime class creation, modification, and generation, as well as dynamic proxy creation and testing mock generation. It functions as an instrumentation library for weaving monitoring, tracing, or mocking logic into classes, and provides a Java agent framework for transforming loaded classes during application startup or execution. The library's capabilities extend to application code instrumentation, method override with fixed logic, and runtime bytecode transformation of already-loaded classes.