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.
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.