VerifyError was thrown by "() -> f1.invoke()"
bitter_fox
bitterfoxc at gmail.com
Thu Dec 1 21:39:10 PST 2011
Hi.
VerifyError was thrown with the message, "Exception in thread "main"
java.lang.VerifyError: Bad return type in method
Main$3.invoke()Ljava/lang/String; at offset 9".
(Compiling is in success)
This is the test program.
// code
public class Main
{
interface Functional0<RET>
{
public RET invoke();
}
public static String getString()
{
return "Hello Lambda World";
}
public static void main(String[] args)
{
Functional0<String> f1 = Main#getString;
Functional0<String> f2 = () -> (String)f1.invoke(); // OK
Functional0<String> f3 = () -> f1.invoke(); // VerifyError
Functional0<String> f4 = f1#invoke; // VerifyError
}
}
Should this program be VerifyError?
I investigated the byte-code by jad.
--------------------Main$2(f2)--------------------
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) disassembler
// Source File Name: Main.java
static class Main$2
implements nctional0
{
Main$2(nctional0 nctional0)
{
// 0 0:aload_0
// 1 1:invokespecial #2 <Method void Object()>
// 2 4:aload_0
// 3 5:aload_1
// 4 6:putfield #3 <Field Main$Functional0 cap$0>
// 5 9:return
}
public String invoke()
{
// 0 0:aload_0
// 1 1:getfield #3 <Field Main$Functional0 cap$0>
// 2 4:invokeinterface #4 <Method Object
Main$Functional0.invoke()>
// 3 9:checkcast #5 <Class String>
// 4 12:areturn
}
public volatile Object invoke()
{
// 0 0:aload_0
// 1 1:invokevirtual #1 <Method String invoke()>
// 2 4:areturn
}
nctional0 cap$0;
}
--------------------Main$3(f3)--------------------
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) disassembler
// Source File Name: Main.java
static class Main$3
implements nctional0
{
Main$3(nctional0 nctional0)
{
// 0 0:aload_0
// 1 1:invokespecial #2 <Method void Object()>
// 2 4:aload_0
// 3 5:aload_1
// 4 6:putfield #3 <Field Main$Functional0 cap$0>
// 5 9:return
}
public String invoke()
{
// 0 0:aload_0
// 1 1:getfield #3 <Field Main$Functional0 cap$0>
// 2 4:invokeinterface #4 <Method Object
Main$Functional0.invoke()>
// 3 9:areturn
}
public volatile Object invoke()
{
// 0 0:aload_0
// 1 1:invokevirtual #1 <Method String invoke()>
// 2 4:areturn
}
nctional0 cap$0;
}
I guess the cause of VerifyError is there is no checkcast in Main$3#String
invoke().
Is this problem already known?
Please check this.
Thank you.
bitter_fox
More information about the lambda-dev
mailing list