problem with lambda expression
Java class file shrinker, optimizer, obfuscator, and preverifier
Brought to you by:
guardsquare
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
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
This keeps ProGuard from optimizing the descriptor of synthetic methods (like the closure method).
Thanks