Byte Buddy

From Wikitia
Jump to navigation Jump to search
Byte Buddy
Developer(s)Rafael Winterhalter
Written inJava
Operating systemCross-platform
TypeBytecode Engineering Library
LicenseApache license (version 2)

Byte Buddy is a Java software library for the manipulation and creation of Java bytecode. Bytecode manipulation can be performed prior to execution or during the runtime of an application. Byte Buddy uses the ObjectWeb ASM library to apply its manipulations but provides a high-level API that avoids the explicit specification of Java bytecode that is required by ObjectWeb ASM. Instead, Byte Buddy uses a domain-specific language to express bytecode manipulation on a high level where the domain language’s verbs lean onto terms of the Java programming language. Byte Buddy is used by a wide-range of commercial and free software products on the Java virtual machine. For example, the library is used by the popular Mockito and Hibernate libraries[1]. Byte Buddy is in particularly popular for creating Java agents, for example by Instana APM [2] Elastic APM [3], where code changes are implemented in regular Java code which is used as template for changing a class’s code. Byte Buddy is part of the OpenJDK Quality Outreach [4] for giving early feedback on upcoming Java releases. The library received a Duke's Choice Award in 2015[5] and its author was distinguished with an Oracle Groundbreaker Award in 2019[6].


Using Byte Buddy, the following code creates and loads a class that extends java.lang.Object and overrides its toString method to return the string Hello World!.

Class<?> dynamicType = new ByteBuddy()
  .intercept(FixedValue.value("Hello World!"))

assertThat(dynamicType.newInstance().toString(), is("Hello World!"));

See also

  • ObjectWeb ASM
  • Byte Code Engineering Library
  • Javassist


  1. "Maven usage overview". MvnRepository.
  2. "Instana agent description". Instana Inc.
  3. "Elastic Search Agent description". Elastic.
  4. "Quality outreach". OpenJDK.
  5. "JAX Enter article mentioning the award (German)". JAX Enter.
  6. "Forbes article on the Groundbreaker award winners of 2019". Forbes.

External links

Add External links

This article "Byte Buddy" is from Wikipedia. The list of its authors can be seen in its historical. Articles taken from Draft Namespace on Wikipedia could be accessed on Wikipedia's Draft Namespace.