在弹出方法堆栈帧后,Throwable对象中的cause字段设置为this

ippsafx7  于 2022-11-07  发布在  其他
关注(0)|答案(1)|浏览(144)

下面是我的openj 9版本:

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.24.0, JRE 11 Linux amd64-64-Bit Compressed References 20210120_910 (JIT enabled, AOT enabled)
OpenJ9   - 345e1b09e
OMR      - 741e94ea8
JCL      - 0a86953833 based on jdk-11.0.10+9)

当我在其他JVM(如HotSpot)中运行以下程序时:

package dacapo6_26;

class Option {
    public boolean isRequired() {
        try {
            OutOfMemoryError var6 = new OutOfMemoryError("java.lang.OutOfMemoryError in ThrowCatch without counter");
            var6.initCause(new OutOfMemoryError("java.lang.OutOfMemoryError as cause exception"));
            throw var6;
        } catch (OutOfMemoryError var3) {
            /*
                The calling of var3.initCause would throw an IllegalStateException,
                since var6 has EXPLICITLY set a cause exception at line 7.
             */
            var3.initCause(new NoSuchMethodException("Cause Exception"));
        }
        return true;
    }
}

public class Harness {
    public static void main(String[] args) {
        try {
            Option option = new Option();
            System.out.println(option.isRequired());
        } catch (Exception var11) {
            /*
                The calling of var11.initCause would throw an IllegalStateException,
                since var11 has IMPLICITLY set a cause exception at line 14.
             */
            var11.initCause(new NoSuchMethodException("Cause Exception"));
            System.err.println("should not reach here");
        }
    }
}

其结果是:

Exception in thread "main" java.lang.IllegalStateException: Can't overwrite cause with java.lang.NoSuchMethodException: Cause Exception
    at java.base/java.lang.Throwable.initCause(Throwable.java:462)
    at dacapo6_26.Harness.main(Harness.java:33)
Caused by: java.lang.IllegalStateException: Can't overwrite cause with java.lang.NoSuchMethodException: Cause Exception
    at java.base/java.lang.Throwable.initCause(Throwable.java:462)
    at dacapo6_26.Option.isRequired(Harness.java:12)
    at dacapo6_26.Harness.main(Harness.java:29)
Caused by: java.lang.OutOfMemoryError: java.lang.OutOfMemoryError in ThrowCatch without counter
    at dacapo6_26.Option.isRequired(Harness.java:6)
    ... 1 more
Caused by: java.lang.OutOfMemoryError: java.lang.OutOfMemoryError as cause exception
    at dacapo6_26.Option.isRequired(Harness.java:7)
    ... 1 more

但在OpenJ 9上运行时,结果是:

should not reach here

结果是预期的,还是OpenJ 9中的一个bug?
OpenJ 9是否丢失了在var3.initCause(new NoSuchMethodException("Cause Exception"));行获得的cause字段信息?
谢谢你!

qhhrdooz

qhhrdooz1#

这一差异已得到纠正;请参阅https://github.com/eclipse-openj9/openj9/pull/14877。OpenJ 9的下一个发行版(0.33.0)中应包含此修复程序。

相关问题