raphw / byte-buddy

Runtime code generation for the Java virtual machine.
https://bytebuddy.net
Apache License 2.0
6.23k stars 804 forks source link

Why doesn't this simple example work? #1630

Closed jimshowalter closed 5 months ago

jimshowalter commented 5 months ago

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 commented 5 months ago

byte-buddy-poc.zip

jimshowalter commented 5 months ago

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?

raphw commented 5 months ago

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

jimshowalter commented 5 months ago

Ah hah.

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

jimshowalter commented 5 months ago

@Argument(0) works.