Compiler bug with nested lambdas and anonymous inner classes?

Keith Amling keith.amling at gmail.com
Mon May 8 20:21:54 UTC 2017


> $ cat Bug.java
> public class Bug {
>     public static void foo() {
>         Runnable r1 = () -> {
>             new Object() {
>                 Runnable r2 = () -> new Object() { };
>             };
>         };
>     }
> }
> $

"Compiles", but bytecode is nonsense (generates aload_0 in static method with
no args) and fails verification:

> $ javac Bug.java
> $ javap -private -c -verbose Bug | grep 'foo()' -A 12
>   public static void foo();
>     descriptor: ()V
>     flags: ACC_PUBLIC, ACC_STATIC
>     Code:
>       stack=1, locals=1, args_size=0
>          0: aload_0
>          1: invokedynamic #2,  0              // InvokeDynamic #0:run:(LBug;)Ljava/lang/Runnable;
>          6: astore_0
>          7: return
>       LineNumberTable:
>         line 3: 0
>         line 8: 7
> 
> $ java Bug
> Error: A JNI error has occurred, please check your installation and try again
> Exception in thread "main" java.lang.VerifyError: Bad local variable type
> Exception Details:
>   Location:
>     Bug.foo()V @0: aload_0
>   Reason:
>     Type top (current frame, locals[0]) is not assignable to reference type
>   Current Frame:
>     bci: @0
>     flags: { }
>     locals: { }
>     stack: { }
>   Bytecode:
>     0x0000000: 2aba 0002 0000 4bb1                    
> 
> 	at java.lang.Class.getDeclaredMethods0(Native Method)
> 	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
> 	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
> 	at java.lang.Class.getMethod0(Class.java:3018)
> 	at java.lang.Class.getMethod(Class.java:1784)
> 	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
> 	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
> $

This with:

> $ uname -a
> Linux trtoje 4.9.0-2-amd64 #1 SMP Debian 4.9.10-1 (2017-02-17) x86_64 GNU/Linux
> $ java -version
> openjdk version "1.8.0_131"
> OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-1-b11)
> OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
> $

Keith


More information about the discuss mailing list