0

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 because the Java class library does not come with a suitable interface type before Java 8 which defines the Function type.

However, when I actually use it (in java 8), an exception is thrown, which appears to be caused by the default methods on Function.

java.lang.IllegalArgumentException: interface java.util.function.Function must declare exactly one non-static method
    at net.bytebuddy.implementation.bind.annotation.Pipe$Binder.onlyMethod(Pipe.java:164)
    at net.bytebuddy.implementation.bind.annotation.Pipe$Binder.install(Pipe.java:145)
    at net.bytebuddy.implementation.bind.annotation.Pipe$Binder.install(Pipe.java:131)

Here is the binding code:

builder.implement(Proxy.class)
       .method(ElementMatchers.any())
       .intercept(MethodDelegation.to(ProxyClassImpl.class)
                                  .appendParameterBinder(Pipe.Binder.install(Function.class)));

It appears that the issue might be that Pipe.Binder.install is looking for all methods which are not static. Perhaps it should exclude default methods also.

Additionally, I tried this with com.google.common.base.Function and got a similar failure because it declares the equals method overridden from Object. So perhaps any methods which exist on Object should also be excluded when trying to identify the single method to pipe through.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
Brett Okken
  • 6,210
  • 1
  • 19
  • 25
  • Can you compile java 8 code? Say a main with `Function f = s -> s;` ? – assylias Feb 03 '16 at 13:55
  • @assylias Yes. The code compiles just fine. The problem is not that Function cannot be found. It is that ByteBuddy does not appear to actually like the methods declared on the Function interface despite the documentation indicating it can be used. – Brett Okken Feb 03 '16 at 13:57

1 Answers1

0

You found a bug in the library that I have introduced in a recent version. This is not supposed to happen and it will be fixed in version 1.1.1 that I release today. Thank you for reporting.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192