RFR: 8370175: State engine terminates when throwing self-caused exception
Francesco Andreuzzi
fandreuzzi at openjdk.org
Wed Oct 29 09:02:12 UTC 2025
On Wed, 29 Oct 2025 06:51:12 GMT, Christian Stein <cstein at openjdk.org> wrote:
> 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)
Marked as reviewed by fandreuzzi (Author).
-------------
PR Review: https://git.openjdk.org/jdk/pull/28037#pullrequestreview-3392275100
More information about the compiler-dev
mailing list