Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if an object was created by byte buddy?

I create an Source object instance using the following code

Source source = new ByteBuddy()
        .subclass(Source.class)            
        .method(named("hello"))
        .intercept(MethodDelegation.to(Target.class))
        .defineMethod("myNewMethod", void.class)
        .intercept(MethodDelegation.to(Target.class))
        .make()
        .load(Source.class.getClassLoader())
        .getLoaded()
        .newInstance();

How can I tell when I analyse a Source object if is created by ByteBuddy ? Is it any marker interface that is implemented or something like this ? The actual class of the generated object is something like Source$ByteBuddy$HFuwCkIQ Thanks !

like image 741
Liviu Carausu Avatar asked Dec 04 '25 15:12

Liviu Carausu


1 Answers

Byte Buddy does not leave any traces in its generated code unless you put such traces into the generated classes. By default, when creating subclasses, Byte Buddy's default naming strategy adds $ByteBuddy$ into the subclass's name but this configuration can change. The easiest way for you to mark your classes would probably be to implement an interface for any class that you generate.

like image 121
Rafael Winterhalter Avatar answered Dec 07 '25 03:12

Rafael Winterhalter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!