首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在弹出方法堆栈框架后,Throwable对象中的原因字段被设置为此

在弹出方法堆栈框架后,Throwable对象中的原因字段被设置为此
EN

Stack Overflow用户
提问于 2022-05-01 09:05:36
回答 1查看 95关注 0票数 1

这是我的openj9版本:

代码语言:javascript
复制
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)

当我在像HotSpot这样的其他JVM中运行以下程序时:

代码语言:javascript
复制
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");
        }
    }
}

结果是:

代码语言:javascript
复制
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

但是在OpenJ9上运行时,结果是:

代码语言:javascript
复制
should not reach here

结果是预期的,还是OpenJ9中的一个bug?

OpenJ9是否遗漏了在var3.initCause(new NoSuchMethodException("Cause Exception"));行获得的cause字段信息?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-05-03 11:47:56

此差异已得到纠正;请参见https://github.com/eclipse-openj9/openj9/pull/14877。修复应该在下一个(0.33.0)版本的OpenJ9中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72075378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档