The latest Byteman documentation (4.0.16) mentions inner classes, but doesn't mention lambdas. I have a rule looking like:
RULE showdir
CLASS ReportService
METHOD lambda$retrieveReport$0
AT ENTRY
IF TRUE
DO System.out.println("XXXXXXXX");
ENDRULE
However it never seems to trigger. When I run bmsubmit without arguments it shows the rule but does not mention a trigger method. I have checked the method name with javap, and it's correct. I can trigger on other non-lambda methods of this class. I'm running AdoptOpenJdk 8 on Alpine Linux.
Does Byteman support lambdas? Do I need to do something else to have the rule trigger?
Update : The behavior was changed in version 4.0.17 (BYTEMAN-416), rules can now be triggered on a lambda
I was able to reproduce the issue using a simple class
BytemanTest
with two lambdas (source code at the end).Short answer
Byteman ignores lambdas because they are marked as 'generated code' by the compiler in the bytecode.
Long answer:
(At least in my tests) Lambdas are flagged, by the compiler, as ACC_SYNTHETIC in the generated bytecode.
From The Java® Virtual Machine Specification :
The following is an excerpt from the output of
javap -v -p -s -c BytemanTest.class
:Byteman ignores methods that have the flag ACC_SYNTHETIC.
This behaviour was (probably) first introduced in this ticket BYTEMAN-58 (In commit ac4cbb4f. The flag test was in the
*Adapter
classes).In Byteman's source code for v4.0.16, The test to match the target method is done in TransformContext#matchTargetMethod and it ignores methods flagged as ACC_SYNTHETIC :
My test class
My byteman rule: