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

can not match lamda method

Open YongwuHe opened this issue 1 year ago • 2 comments

When I need to do an target code usage search for all the methods in a certain class. I can't match to the lamda method, so some object codes cannot be replaced. Is there any way I can match to the lambda method. ex: memberSubstitution.on(isMethod())

@raphw

YongwuHe avatar Aug 18 '23 06:08 YongwuHe

This would require to match a invokedynamic instruction. This is not possible today, but could be added.

raphw avatar Sep 09 '23 18:09 raphw

This is how we do it now: @raphw

// byte buddy will ignore the method which is lambda. replace method need search all method(include lambda).
private void removeIgnoredMethods(DynamicType.Builder<?> builder) {
     try {
         if (ignoredMethods == null) {
             ignoredMethods = DynamicType.Builder.AbstractBase.Adapter.class.getDeclaredField("ignoredMethods");
             ignoredMethods.setAccessible(true);
         }
         ignoredMethods.set(builder, new LatentMatcher.Resolved<MethodDescription>(none()));
     } catch (Exception e) {
         LogManager.warn("removeIgnoredMethods", e);
     }
 }

YongwuHe avatar Sep 14 '23 02:09 YongwuHe