The cause field in Throwable object is set to this after popping method stack frames

230 views Asked by At

Here is my openj9 version:

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)

When I run the following program in some other JVMs like 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");
        }
    }
}

The result is:

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

But when running on the OpenJ9, the result is:

should not reach here

Is the result expected, or a bug in OpenJ9?

Does OpenJ9 miss the cause field information gained at line var3.initCause(new NoSuchMethodException("Cause Exception"));?

Thanks!

1

There are 1 answers

0
Keith W. Campbell On

This difference has been corrected; see https://github.com/eclipse-openj9/openj9/pull/14877. The fix should be in the next (0.33.0) release of OpenJ9.