Menu ▾ ▴

#540 problem with lambda expression

v5.0
closed-fixed
None
6
2015-02-01
2014-09-04
No

Hello,
I have problem with lambda expression.
Java 1.8.20, win 7

public class J8ProGuardLambda {
    public static void main(String[] args) {
        J8Listener l = e->System.out.println("123");
        l.actionPerformed(null);
    }
    public static interface J8Listener {
        public void actionPerformed(Object e);
    }
}

I created jar and obfucated it with applications.pro.
Now run java -jar out.jar gets exception:

Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception
        at java.lang.invoke.CallSite.makeSite(Unknown Source)
        at java.lang.invoke.MethodHandleNatives.linkCallSite(Unknown Source)
        at java8test.J8ProGuardLambda.main(SourceFile:5)
Caused by: java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method invokeStatic
java8test.J8ProGuardLambda.a:()void; 0 captured parameters, 1 functional interface method parameters, 0 implementation parameters
        at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(Unknown Source)
        at java.lang.invoke.LambdaMetafactory.metafactory(Unknown Source)
        ... 3 more

Regards
Adam

Discussion

  • Eric Lafortune

    Eric Lafortune - 2014-09-09

    Thanks for your report. ProGuard is removing the unused parameter from the closure. This is tricky, since the compiler and the JVM are using a type of reflection to link the interface with the closure. For now, you can work around the problem with

    -keepclassmembers,allowshrinking,allowobfuscation class * {
        synthetic <methods>;
    }
    

    This keeps ProGuard from optimizing the descriptor of synthetic methods (like the closure method).

     
  • Eric Lafortune

    Eric Lafortune - 2014-09-09
    • status: open --> open-accepted
    • assigned_to: Eric Lafortune
    • Priority: 5 --> 6
     
  • Adam Bartoszewicz

    Thanks

     
  • Eric Lafortune

    Eric Lafortune - 2014-10-27
    • Status: open-accepted --> closed-fixed
     

Log in to post a comment.