Compiler bug: Instantiating non-static inner classes using constructor references inside lambdas
Victor Williams Stafusa da Silva
victorwssilva at gmail.com
Mon Nov 3 02:12:39 UTC 2014
Hi, I used javac 1.8.0_25 with this code:
package com.example;
> import java.util.function.Function;
> public class MakeVerifyError {
> public void foo() {
> Boom es = new Boom();
> go(() -> es.test(Crash::new));
> }
> private static void go(Runnable run) {}
> public class Crash { public Crash(Boom e) {} }
> public static class Boom { public void test(Function<Boom, ?> ctor) {}
> }
> public static void main(String[] args) {}
> }
And this was the result:
java.lang.VerifyError: Bad type on operand stack
> Exception Details:
> Location:
>
> com/example/MakeVerifyError.lambda$foo$0(Lcom/example/MakeVerifyError$Boom;)V
> @2: invokedynamic
> Reason:
> Type 'com/example/MakeVerifyError$Boom' (current frame, stack[1]) is
> not assignable to 'com/example/MakeVerifyError'
> Current Frame:
> bci: @2
> flags: { }
> locals: { 'com/example/MakeVerifyError$Boom' }
> stack: { 'com/example/MakeVerifyError$Boom',
> 'com/example/MakeVerifyError$Boom' }
> Bytecode:
> 0x0000000: 2a2a ba00 0600 00b6 0007 b1
> at java.lang.Class.getDeclaredMethods0(Native Method)
> at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
> at java.lang.Class.privateGetMethodRecursive(Class.java:3040)
> at java.lang.Class.getMethod0(Class.java:3010)
> at java.lang.Class.getMethod(Class.java:1776)
> at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
> at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
> Exception in thread "main" Java Result: 1
If the 'static' modifier is added to the Crash class, it works fine.
If the 'test' method call is moved to outside the lambda, it works fine.
If the Boom object is instantiated inside the lambda, it fails to load the
class:
Error: Could not find or load main class com.example.MakeVerifyError
> Java Result: 1
So, obviously this looks like a compiler bug.
Do somebody already saw that before?
Victor Williams Stafusa da Silva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20141103/c189f4a1/attachment-0001.html>
More information about the compiler-dev
mailing list