Integrated: 8370175: State engine terminates when throwing self-caused exception

Christian Stein cstein at openjdk.org
Wed Nov 5 06:26:16 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)

This pull request has now been integrated.

Changeset: a0e70c4e
Author:    Christian Stein <cstein at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/a0e70c4e9489fc3d8f35c3aec9423fe0839ed0bd
Stats:     30 lines in 2 files changed: 25 ins; 0 del; 5 mod

8370175: State engine terminates when throwing self-caused exception

Reviewed-by: jlahoda, fandreuzzi

-------------

PR: https://git.openjdk.org/jdk/pull/28037


More information about the compiler-dev mailing list