Questions tagged [byte-buddy]

Byte Buddy is a code generation and manipulation library for creating and modifying Java classes during the runtime of a Java application and without the help of a compiler. Byte Buddy allows the creation of arbitrary classes and is not limited to implementing interfaces for the creation of runtime proxies. Furthermore, Byte Buddy offers a convenient API for changing classes either manually, using a Java agent or during a build.

Byte Buddy is a code generation and manipulation library for creating and modifiying Java classes during the runtime of a Java application and without the help of a compiler. Other than the code generation utilities that ship with the Java Class Library, Byte Buddy allows the creation of arbitrary classes and is not limited to implementing interfaces for the creation of runtime proxies. Furthermore, Byte Buddy offers a convenient API for changing classes either manually, using a Java agent or during a build.

In order to use Byte Buddy, one does not require an understanding of Java byte code or the class file format. In contrast, Byte Buddy's API aims for code that is concise and easy to understand for everybody. Nevertheless, Byte Buddy remains fully customizable down to the possibility of defining custom byte code. Furthermore, the API was designed to be as non-intrusive as possible and as a result, Byte Buddy does not leave any trace in the classes that were created by it. For this reason, the generated classes can exist without requiring Byte Buddy on the class path. Because of this feature, Byte Buddy's mascot was chosen to be a ghost.

Byte Buddy is written in Java 6 but supports the generation of classes for any Java version. Byte Buddy is a light-weight library and only depends on the visitor API of the Java byte code parser library ASM which does itself not require any further dependencies.

749 questions
-1
votes
1 answer

Fail to load class using ByteBuddy

I'm trying to load some java built-in classes like Object and Calendar Class proxied = new ByteBuddy() .subclass(Calendar.class) …
zxzxzx
  • 1
  • 1
-1
votes
1 answer

Is there a way to get the method signature with Advice API?

I'm currently working on a Java agent whose job is to track (and let's say print) the current location of each thread in the program. As an example, if I have a Java program like so : public class MyClass { public static void a(String s) { …
AntoineG
  • 93
  • 7
-1
votes
1 answer

add behavior to method with ByteBuddy

Given Sample.someMethod(...) and InvocationHandler decoration, I want to create a dynamic subclass that overrides someMethod with someMethod(...) { decoration.invoke(...); super.someMethod(...); } My code looks like this: Class
morgwai
  • 2,513
  • 4
  • 25
  • 31
-1
votes
1 answer

Enhance POJO with Bytecode manipulation

I need to do some "bytecode hacking" to inject something into a POJO without adding a "visible" property. Consider this code: public class Entity { private Multimap linkMap; public void setLink(String linkName, Entity entity)…
Fireburn
  • 981
  • 6
  • 20
-1
votes
1 answer

Dynamically create class and method using Bytebuddy

I am new to bytebuddy, I would like to dynamically create a class and execute code like below using byte buddy. public class Formulas{ public double formula1234(FormulaAPI apiReference) { if(apiReference.getId() >…
javaseeker
  • 73
  • 1
  • 9
-1
votes
2 answers

Getting field name as string for already defined class. Is that possible?

Using byte-buddy is that possible to reference field name as string. Here is what I m trying. public class MyClass { public int x; public int y; } public String getMethodName() { Class clazz = MyClass.class; return…
LaraFlow
  • 352
  • 5
  • 15
-1
votes
1 answer

log and track proxy creation in JVM

I have a class-loading problem in my app. We are using custom classloader and all is closed correctly but dynamic classes (com.sun.proxy.* and org.springframework.core.$Proxy) are generated pretty wildly and metaspace keeps growing to the point…
kosta5
  • 1,129
  • 3
  • 14
  • 36
-1
votes
1 answer

Append value to JDBC connection property

Looking for an example (or suggestions) on how to use ByteBuddy to intercept and append a value on a JDBC connection property. The goal is to be able to use a JavaAgent to append a unique value for transaction correlation WITHOUT client code…
-1
votes
1 answer

Private method interception using byte-buddy

How can I Intercept private methods using byte-buddy? I am able to intercept all the public methods using Advice but when I submit private method signature for interception it is not intercepted?
ravi k
  • 31
  • 4
-1
votes
1 answer

Modifying the returned value of a static method

I need to intercept a method call to a static method. My new method needs to invoke the original implementation of the method, do some work with what it returns and return the modified value. My problem is with the "invoke the original…
Hugi
  • 202
  • 2
  • 7
-1
votes
1 answer

I'm getting java.lang.IllegalArgumentException

I'm getting following error: java.lang.IllegalArgumentException: None of [static java.lang.String com.runtime.MyInterceptor.intercept()] allows for delegation from public java.lang.String java.lang.Object.toString() I don't know what mistake I'm…
Tirumalesh
  • 95
  • 1
  • 17
-2
votes
1 answer

How to redefine a class with Byte-buddy to add an additional method

If I have the following Class named Dog public class Dog { private String name = "Spike"; private int age = 3; public Dog() {} public String getName() { return name; } } How would I declare ByteBuddy for use in a javaagent to…
stackoverflow
  • 18,348
  • 50
  • 129
  • 196
-2
votes
1 answer

Can't install byte-buddy-agent on java 9

Byte buddy says that it works with java 9, there is even code for it: ByteBuddyAgent.install(ForJigsawVm.INSTANCE) I use simple ByteBuddyAgent.install() that should check all possibilities (including java 9/jigsaw), but it fails. I'm doing something…
GotoFinal
  • 3,585
  • 2
  • 18
  • 33
1 2 3
49
50