Hello Raphael,
I have a Java agent that instruments the code of one of my servers using Advice visitors. For a new usecase, I need to add a method to a class (note: for this UC I want to work directly on my instrumented class with no a proxy class).
First attempt (Advice visitor)
xxx.transform((builder, typeDescription, classLoader, module) -> builder
.defineMethod("mynewmethod", MyClass.class, Visibility.PUBLIC)
.withParameters(...)
.intercept(Advice.to(_MyAdvice.class)));
(_MyAdvice contains a basic advice)
=> With the kind of visitor, i obtain the following error (Note: all other instrumented classes are well transformed):
[Byte Buddy] ERROR xxx [sun.misc.Launcher$AppClassLoader@18b4aac2, null, loaded=true]
java.lang.IllegalStateException: Cannot call super (or default) method for public MyClass.mynewmethod
Second attempt (MethodDelegation)
With intercept(MethodDelegation.to(_MyInterceptor.class))); and, a basic @RuntimeType interceptor.
=> With this kind of delegation, MyClass is transformed ([Byte Buddy] TRANSFORM MyClass [sun.misc.Launcher$AppClassLoader@18b4aac2, null, loaded=true]) but all other instrumented classes are not transformed
Final attempt : if i put the delegation on an existing method of MyClass;
all instrumented classes are well transformed... but that's not my UC ;).
So i'm a bit confused :(
Regard,
Philippe