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
0
votes
1 answer

How to make ByteBuddy created sub-interface inherit type annotations?

I have this pseudo-test to create a sub-interface and I want to copy annotations from interface S but it doesn't work. What am I doing wrong? import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; import…
Pogo19
  • 1,453
  • 1
  • 10
  • 13
0
votes
1 answer

ClassNotFoundException with Mockito 2 in OSGI

When I Try to run junit plugin tests in eclipse using Mockito 2 (version 2.0.54 beta), calling org.mockito.Mockito.mock(Class, MockSettings) fails with stack trace above. I manage to workaround the issue by doing this ClassLoader loader =…
0
votes
1 answer

Field writer interceptor

I'am studying Byte Buddy and I am trying to replace CGLib by it. I want to know if there is a way to implement to intercept writing to any field. I do not know the field type and I do not want to change the assigned value. I only want to log field…
Marcelo D. Ré
  • 181
  • 2
  • 10
0
votes
1 answer

Bytebuddy intercept exception throw

I would like to intercept exception throw and log it using bytebuddy. Is it possible? If not what are the other tools that would allow me to do that?
user3364192
  • 3,783
  • 2
  • 21
  • 30
0
votes
2 answers

How to track the state of a POJO using code generation

We looking for a solution to track the state of a client POJO instance in a performant manner. What we expect is: every time a change is made on a POJO this state is made by using setters. We created an OGNL-based watching / event-bus and when…
Elad Hirsch
  • 294
  • 1
  • 16
0
votes
1 answer

Intercepting all Android Activity onCreate

Been trying to hook up android with byte-buddy but having issues with my goal; That goal being to intercept onCreate, and then to add a Log.d(TAG, "Message") to all Activities getting created. Updated with imports package…
Hiam
  • 303
  • 1
  • 4
  • 12
0
votes
1 answer

Byte-Buddy-Android for current Dx

I'm currently using byte-buddy, byte-buddy-android and Android's dx_1.7 library. The dx_1.7.jar is out of date (2012) and I wonder if someone has already built a new byte-buddy-android.jar that works with a current dx.jar (not dx_1.7.jar) provided…
Key
  • 139
  • 1
  • 9
0
votes
1 answer

ByteBuddy Pipe.Binder fails with java 8 Function

The documentation on ByteBuddy for using a Pipe annotation with method delegation states that java.util.function.Function is a suitable type to be bound for use with Pipe. The @Pipe annotation is not preregistered with the MethodDelegation …
Brett Okken
  • 6,210
  • 1
  • 19
  • 25
0
votes
2 answers

ByteBuddy not finding some methods

I've created the following agent which supposedly rebases every class and transforms every method, using the ByteBuddy example LogInterceptor (which just prints the name of the method being called): public static void main(String[] args) { …
Edu Garcia
  • 453
  • 7
  • 21
0
votes
2 answers

Bytebuddy - class redefinition in runtime

Can you please tell me if this is possible scenario with byte-buddy: Java program is run. Standard java POJO classes with lots of properties are loaded. ByteBuddy - in runtime modify each class replacing property types e.g. int and Integer with…
Marko Kraljevic
  • 401
  • 4
  • 19
0
votes
2 answers

Delegation to setter on abstract base class results in VerifyError on load

This question is related to my previous quesiton here: How to create a default constructor with Byte Buddy I am creating a subclass which first sets up some context before delegatig method invocation to some instance. This already works quite well…
leozilla
  • 1,296
  • 2
  • 19
  • 29
0
votes
2 answers

Bind byte buddy method delegation only to methods with annotated parameters

I want to decorate existing objects so that method calls are automatically validated. I already managed to delegate method call to an interceptor that calls Hibernate validator and so far it works fine: public class HibernateBeanValidator implements…
starko
  • 11
  • 4
0
votes
1 answer

Change the superclass of a class at runtime

Can i use Byte Buddy to enhance a class at runtime by inheriting from an abstract class? @AggregateRoot public class Organization { } I should be able to intercept all instances of Organization and enhance it by inheriting from an abstract class…
FFL
  • 669
  • 7
  • 22
0
votes
2 answers

Is there a runtime proxy creation library that supports to retain annotations of the proxied class?

When creating a proxy with for example cglib or javassist proxies, this proxy is implemented by creating a subclass of the proxy target. However, this means that the annotations on this proxy are lost. This is problematic when a class is processed…
Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
-1
votes
1 answer

Using bytebuddy reflection to bypass file string check

There's this problem in Codewars https://www.codewars.com/kata/58a3fa665973c2a6e80000c4/train/java We will have to just square root a very big number. Of course all of us would think about BigInteger.sqrt - but the challenge itself reject these…
Luka
  • 55
  • 1
  • 7
1 2 3
49
50