来自无害语句的java 14 verifyerror

1rhkuytd  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(218)

尝试从eclipse 2020-06(使用jdk-14.0.1)运行以下代码段时(在成功编译后):

import java.util.*;
public class VerifyErrorTesting {
    public static void main(String[] args) {
        new ArrayList<Double>().add(
            switch("t") {
            case "t" -> Double.valueOf(0);
            default -> 1d;
            }
        );
    }
}

我得到以下信息 VerifyError :

Error: Unable to initialize main class othergoofs.VerifyErrorTesting in module goofer
Caused by: java.lang.VerifyError: Instruction type does not match stack map
Exception Details:
  Location:
    othergoofs/VerifyErrorTesting.main([Ljava/lang/String;)V @58: invokevirtual
  Reason:
    Current frame's stack size doesn't match stackmap.
  Current Frame:
    bci: @58
    flags: { }
    locals: { '[Ljava/lang/String;', 'java/lang/String' }
    stack: { 'java/util/ArrayList', 'java/lang/Double' }
  Stackmap Frame:
    bci: @58
    flags: { }
    locals: { '[Ljava/lang/String;' }
    stack: { 'java/util/ArrayList', double, double_2nd }
  Bytecode:
    0000000: bb00 1059 b700 1212 1359 4cb6 0015 ab00
    0000010: 0000 0028 0000 0001 0000 0074 0000 0012
    0000020: 2b12 13b6 001b 9a00 06a7 000d 0eb8 001f
    0000030: b600 25a7 0007 0fb8 001f b600 2957 b1  
  Stackmap Table:
    full_frame(@32,{Object[#47],Object[#22]},{Object[#16]})
    same_locals_1_stack_item_frame(@44,Object[#16])
    same_locals_1_stack_item_frame(@54,Object[#16])
    full_frame(@58,{Object[#47]},{Object[#16],Double})

我试过用javac编译相同的代码,但运行起来没有问题;该错误仅在从eclipse运行时发生。当我稍微修改代码时,错误就消失了。例如,改变 Double.valueOf(0)0d 运行无错误。改变 1dDouble.valueOf(1) 也可以正常运行。更换 new ArrayList<Double>().addDouble d= 或者 double d= 运行也很好。
我的问题是:是什么导致了 VerifyError ?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题