byte-buddy
byte-buddy copied to clipboard
Problem with LambdaInstrumentationStrategy.ENABLED
Hello.
When instrumenting lambdas, i get the following Exception:
Exception in thread "main" java.lang.AbstractMethodError: Receiver class ByteBuddyLambdaTest$StringFunction$$Lambda$ByteBuddy$1/0x000002b6c81495c0 does not define or inherit an implementation of the resolved method 'java.lang.Object apply(java.lang.Object)' of interface ByteBuddyLambdaTest$StringFunction.
at ByteBuddyLambdaTest.main(ByteBuddyLambdaTest.java:13)
Minimal code to reproduce the problem is as follows:
import java.util.function.Function;
import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.agent.builder.AgentBuilder.LambdaInstrumentationStrategy;
public class ByteBuddyLambdaTest {
public static void main(String[] args) {
new AgentBuilder.Default()
.with(LambdaInstrumentationStrategy.ENABLED)
.installOn(ByteBuddyAgent.install());
StringFunction.TEST.apply("test");
}
interface StringFunction extends Function<String, String> {
StringFunction TEST = System::getProperty;
}
}
It seems to be due to the interface extending a generified lambda (i.e. Function<String, String>).
Somehow the code produced by the LambdaInstrumentationStrategy doesn't contain the right parameter types, I guess?
Thanks in advance Alex
I have not put a lot of effort into this strategy lately. It adjusts too much internal API and will stop to work in any future release. I would recommend against using it, and I will likely remove it from a future release. Possibly, you can try to implement something similar yourself.