JDK-8295857 : Clarify that cleanup code can be skipped when the JVM terminates (e.g. when calling halt())
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 20
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-10-24
  • Updated: 2022-12-19
  • Resolved: 2022-12-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20 JDK 21
20 b28Fixed 21Fixed
Related Reports
Relates :  
Description
JDK-8290036 documented  the shutdown sequence, noting that calling Runtime.halt() skips the shutdown sequence and immediately terminates the VM. Thus, "threads' current methods do not complete normally or abruptly; no finally clause of any method is executed".

One ramification of this is that resources within try-with-resource blocks will not be released. Some developers may realize this implication of calling halt(), but it would be better to state it explicitly.


Comments
Changeset: bf78f716 Author: Brent Christian <bchristi@openjdk.org> Date: 2022-12-13 19:07:44 +0000 URL: https://git.openjdk.org/jdk20/commit/bf78f716bd3e58df24ff1e6f4a0104025379f821
13-12-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk20/pull/19 Date: 2022-12-12 19:51:22 +0000
12-12-2022

OK, updated that passage too
22-11-2022

Your latest update did not address my concern. It is this list that needs to clearly indicate it is just examples: * {@linkplain Thread.UncaughtExceptionHandler Uncaught exception handlers} are not run, * no {@code finally} clause of any method is executed, and try-with-resources * blocks do not {@linkplain AutoCloseable close} their resources. Thanks
21-11-2022

I will clearly indicate that it's not a complete list.
18-11-2022

Personally, I don't think it is necessary to add to the list of things that won't happen when a thread is "immediately prevented from executing any further Java code" due to VM termination.The more you add, the more people take it as a proscriptive list and so anything not listed may actually still happen. If you insist on expanding this then the language must clearly show that these are just examples of things that won't happen, not a complete list.
17-11-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/11218 Date: 2022-11-17 19:25:42 +0000
17-11-2022

[~bchristi] Perhaps you would like to work on this.
28-10-2022