byte-buddy icon indicating copy to clipboard operation
byte-buddy copied to clipboard

Why doesn't this simple example work?

Open jimshowalter opened this issue 1 year ago • 1 comments

When we try to run EntityModificationUtilsTest, it fails like this for some reason:

java.lang.IllegalArgumentException: None of [public static void org.foo.bytebuddypoc.SetterInterceptor.interceptSetter(java.lang.reflect.Method,java.lang.Object)] allows for delegation from public void org.foo.bytebuddypoc.TestEntity.setFoo(java.lang.String)

What are we doing wrong?

jimshowalter avatar May 01 '24 22:05 jimshowalter

It works if the second parameter to the interceptor is changed to @AllArguments Object[] args, but if isSetter() returns true, wouldn't there always only be one argument?

jimshowalter avatar May 02 '24 18:05 jimshowalter

You probably want to annotate the second parameter as well using @Argument(0)

raphw avatar May 02 '24 18:05 raphw

Ah hah.

We couldn't find examples of setter interceptors in the documentation, so we had to get examples from secondary sources.

jimshowalter avatar May 02 '24 18:05 jimshowalter

@Argument(0) works.

jimshowalter avatar May 02 '24 18:05 jimshowalter