VerifyError: Bad type on operand stack
Paul Sandoz
paul.sandoz at oracle.com
Thu Sep 20 05:44:47 PDT 2012
Hi,
The following code compiles but fails to run:
import java.util.functions.Factory;
public class A {
public static void main(String[] args) {
Factory<A> op = () -> new A() {};
}
}
--
$ $JAVA_HOME/bin/java -cp . A
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
Location:
A.main([Ljava/lang/String;)V @1: invokedynamic
Reason:
Type '[Ljava/lang/String;' (current frame, stack[0]) is not assignable to 'A'
Current Frame:
bci: @1
flags: { }
locals: { '[Ljava/lang/String;' }
stack: { '[Ljava/lang/String;' }
Bytecode:
0000000: 2aba 0002 0000 4cb1
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2441)
at java.lang.Class.getMethod0(Class.java:2684)
at java.lang.Class.getMethod(Class.java:1617)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
--
I think the cause is the anonymous inner class within the lambda expression
Paul.
$ $JAVA_HOME/bin/javap -v -l -c -cp . A
Classfile /Users/sandoz/tmp/A.class
Last modified Sep 20, 2012; size 1190 bytes
MD5 checksum fbd46bc0e6a8eb98f42e24dd4d046dbf
Compiled from "A.java"
public class A
SourceFile: "A.java"
InnerClasses:
static #3; //class A$1
public static final #53= #52 of #58; //Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
BootstrapMethods:
0: #30 invokestatic java/lang/invoke/LambdaMetafactory.metaFactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
Method arguments:
#31 invokeinterface java/util/functions/Factory.make:()Ljava/lang/Object;
#32 invokevirtual A.lambda$0:()LA;
#33 ()LA;
minor version: 0
major version: 51
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #6.#28 // java/lang/Object."<init>":()V
#2 = InvokeDynamic #0:#34 // #0:lambda:(LA;)Ljava/util/functions/Factory;
#3 = Class #35 // A$1
#4 = Methodref #3.#36 // A$1."<init>":(LA;)V
#5 = Class #37 // A
#6 = Class #38 // java/lang/Object
#7 = Utf8
#8 = Utf8 InnerClasses
#9 = Utf8 <init>
#10 = Utf8 ()V
#11 = Utf8 Code
#12 = Utf8 LineNumberTable
#13 = Utf8 LocalVariableTable
#14 = Utf8 this
#15 = Utf8 LA;
#16 = Utf8 main
#17 = Utf8 ([Ljava/lang/String;)V
#18 = Utf8 args
#19 = Utf8 [Ljava/lang/String;
#20 = Utf8 op
#21 = Utf8 Ljava/util/functions/Factory;
#22 = Utf8 LocalVariableTypeTable
#23 = Utf8 Ljava/util/functions/Factory<LA;>;
#24 = Utf8 lambda$0
#25 = Utf8 ()LA;
#26 = Utf8 SourceFile
#27 = Utf8 A.java
#28 = NameAndType #9:#10 // "<init>":()V
#29 = Utf8 BootstrapMethods
#30 = MethodHandle #6:#39 // invokestatic java/lang/invoke/LambdaMetafactory.metaFactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#31 = MethodHandle #9:#40 // invokeinterface java/util/functions/Factory.make:()Ljava/lang/Object;
#32 = MethodHandle #5:#41 // invokevirtual A.lambda$0:()LA;
#33 = MethodType #25 // ()LA;
#34 = NameAndType #42:#43 // lambda:(LA;)Ljava/util/functions/Factory;
#35 = Utf8 A$1
#36 = NameAndType #9:#44 // "<init>":(LA;)V
#37 = Utf8 A
#38 = Utf8 java/lang/Object
#39 = Methodref #45.#46 // java/lang/invoke/LambdaMetafactory.metaFactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#40 = InterfaceMethodref #47.#48 // java/util/functions/Factory.make:()Ljava/lang/Object;
#41 = Methodref #5.#49 // A.lambda$0:()LA;
#42 = Utf8 lambda
#43 = Utf8 (LA;)Ljava/util/functions/Factory;
#44 = Utf8 (LA;)V
#45 = Class #50 // java/lang/invoke/LambdaMetafactory
#46 = NameAndType #51:#54 // metaFactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#47 = Class #55 // java/util/functions/Factory
#48 = NameAndType #56:#57 // make:()Ljava/lang/Object;
#49 = NameAndType #24:#25 // lambda$0:()LA;
#50 = Utf8 java/lang/invoke/LambdaMetafactory
#51 = Utf8 metaFactory
#52 = Class #59 // java/lang/invoke/MethodHandles$Lookup
#53 = Utf8 Lookup
#54 = Utf8 (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
#55 = Utf8 java/util/functions/Factory
#56 = Utf8 make
#57 = Utf8 ()Ljava/lang/Object;
#58 = Class #60 // java/lang/invoke/MethodHandles
#59 = Utf8 java/lang/invoke/MethodHandles$Lookup
#60 = Utf8 java/lang/invoke/MethodHandles
{
public A();
flags: ACC_PUBLIC
LineNumberTable:
line 3: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this LA;
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 3: 0
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this LA;
public static void main(java.lang.String[]);
flags: ACC_PUBLIC, ACC_STATIC
LineNumberTable:
line 5: 0
line 6: 7
LocalVariableTable:
Start Length Slot Name Signature
0 8 0 args [Ljava/lang/String;
7 1 1 op Ljava/util/functions/Factory;
Code:
stack=1, locals=2, args_size=1
0: aload_0
1: invokedynamic #2, 0 // InvokeDynamic #0:lambda:(LA;)Ljava/util/functions/Factory;
6: astore_1
7: return
LineNumberTable:
line 5: 0
line 6: 7
LocalVariableTable:
Start Length Slot Name Signature
0 8 0 args [Ljava/lang/String;
7 1 1 op Ljava/util/functions/Factory;
LocalVariableTypeTable:
Start Length Slot Name Signature
7 1 1 op Ljava/util/functions/Factory<LA;>;
}
More information about the lambda-dev
mailing list