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

Problem with LambdaInstrumentationStrategy.ENABLED

Open ap-actoron opened this issue 2 months ago • 1 comments

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

ap-actoron avatar Nov 04 '25 09:11 ap-actoron

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.

raphw avatar Nov 04 '25 17:11 raphw