RFR: 8370175: State engine terminates when throwing self-caused exception
Christian Stein
cstein at openjdk.org
Wed Oct 29 06:58:31 UTC 2025
Please review this change to prevent an engine termination in `jshell` in a self-causation exception scenario.
Prior to the fix, a non-null cause exception was unconditionally converted and used. Now, a set with identity equalitiy semantics is guarding the process, by breaking a recursive chains when a reference cycle is detected. The guard implementation is inspired by the one used in [java.base/java.lang.Throwable](https://github.com/openjdk/jdk/blob/0687f120cc324f35fe43d811b6beb4184fd854ec/src/java.base/share/classes/java/lang/Throwable.java#L689-L693)
Note that a direct self-causation state is already prevented at the `Throwable::initCause` method level:
jshell> var t = new Throwable()
t ==> java.lang.Throwable
jshell> t.initCause(t)
| Exception java.lang.IllegalArgumentException: Self-causation not permitted
| at Throwable.initCause (Throwable.java:492)
| at (#8:1)
| Caused by: java.lang.Throwable
| at do_it$Aux (#7:1)
| at (#7:1)
-------------
Commit messages:
- Compact implementation and add test
- 8370175: State engine terminates when throwing self-caused exception
Changes: https://git.openjdk.org/jdk/pull/28037/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=28037&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8370175
Stats: 30 lines in 2 files changed: 25 ins; 0 del; 5 mod
Patch: https://git.openjdk.org/jdk/pull/28037.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/28037/head:pull/28037
PR: https://git.openjdk.org/jdk/pull/28037
More information about the compiler-dev
mailing list