Skip to content

Conversation

@sormuras
Copy link
Member

@sormuras sormuras commented Oct 29, 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

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) 

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8370175: State engine terminates when throwing self-caused exception (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28037/head:pull/28037
$ git checkout pull/28037

Update a local copy of the PR:
$ git checkout pull/28037
$ git pull https://git.openjdk.org/jdk.git pull/28037/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28037

View PR using the GUI difftool:
$ git pr show -t 28037

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28037.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 29, 2025

👋 Welcome back cstein! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 29, 2025

@sormuras This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8370175: State engine terminates when throwing self-caused exception Reviewed-by: jlahoda, fandreuzzi 

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 22 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Oct 29, 2025
@openjdk
Copy link

openjdk bot commented Oct 29, 2025

@sormuras The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 29, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 29, 2025

Webrevs

Copy link
Contributor

@lahodaj lahodaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 29, 2025
@pavelrappo
Copy link
Member

As a reporter, thanks for taking care of this. One note is that Throwable.printStackTrace also takes care of cycles in suppressed trees. JShell does not seem to print suppressed exceptions, but if it ever does, we will need to treat them the same way.

jshell> var e1 = new Error(); ...> var e2 = new Error(); ...> e1.addSuppressed(e2); ...> e2.addSuppressed(e1); ...> e1.printStackTrace(); e1 ==> java.lang.Error e2 ==> java.lang.Error java.lang.Error	at REPL.$JShell$2.do_it$Aux($JShell$2.java:6)	at REPL.$JShell$2.do_it$($JShell$2.java:11)	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)	at java.base/java.lang.reflect.Method.invoke(Method.java:565)	at jdk.jshell/jdk.jshell.execution.DirectExecutionControl.invoke(DirectExecutionControl.java:227)	at jdk.jshell/jdk.jshell.execution.RemoteExecutionControl.invoke(RemoteExecutionControl.java:121)	at jdk.jshell/jdk.jshell.execution.DirectExecutionControl.invoke(DirectExecutionControl.java:125)	at jdk.jshell/jdk.jshell.execution.ExecutionControlForwarder.processCommand(ExecutionControlForwarder.java:148)	at jdk.jshell/jdk.jshell.execution.ExecutionControlForwarder.commandLoop(ExecutionControlForwarder.java:266)	at jdk.jshell/jdk.jshell.execution.Util.forwardExecutionControl(Util.java:78)	at jdk.jshell/jdk.jshell.execution.Util.forwardExecutionControlAndIO(Util.java:148)	at jdk.jshell/jdk.jshell.execution.RemoteExecutionControl.main(RemoteExecutionControl.java:74)	Suppressed: java.lang.Error	at REPL.$JShell$3.do_it$Aux($JShell$3.java:6)	at REPL.$JShell$3.do_it$($JShell$3.java:11)	... 10 more	Suppressed: [CIRCULAR REFERENCE: java.lang.Error] jshell> throw e1 | Exception java.lang.Error | at do_it$Aux (#1:1) | at (#1:1) 

Btw, why doesn't JShell print suppressed exceptions? Seems helpful in try-with-resources blocks.

@sormuras
Copy link
Member Author

As a reporter, thanks for taking care of this.

Welcome, Pavel!

[...]
Btw, why doesn't JShell print suppressed exceptions? Seems helpful in try-with-resources blocks.

Should be discussed in a dedicated JBS issue or thread on the appropriated mailing list. As kulla-dev is archived, please send a mail to compiler-dev instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler compiler-dev@openjdk.org ready Pull request is ready to be integrated rfr Pull request is ready for review

4 participants