JDK-8293843 : Degrade Thread.stop
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 20
  • Submitted: 2022-09-15
  • Updated: 2022-09-26
  • Resolved: 2022-09-22
Related Reports
CSR :  
Relates :  
Description
Summary
-------

Degrade `Thread.stop()` to throw `UnsupportedOperationException` (UOE) unconditionally. Deprecate the error `ThreadDeath`, for removal.


Problem
-------

Thread.stop dates from JDK 1.0 as an API to "stop" a victim thread by causing the victim thread to throw the error ThreadDeath. It is inherently unsafe with all "stop" methods deprecated since JDK 1.2 with a link to the "Java Thread Primitive Deprecation" page that explains the reasoning for the deprecation.

The recent steps on degrading and removing the feature are:

- Thread.stop(Throwable) was degraded to throw UOE in Java 8 and removed in Java 11.

- ThreadGroup.stop() was degraded to throw UOE in Java 19.

The remaining method is the no-arg Thread.stop(). This method is terminally deprecated since Java 18. In Java 19 it was specified to throw UOE when invoked on a virtual Thread.


Solution
--------

- Degrade the no-arg Thread.stop to throw UOE.

- Deprecate ThreadDeath, for removal.

- Update the specification of ThreadGroup.uncaughtException to remove its special handling for ThreadDeath.

- Remove the target permission name  "stopThread" from the table of names in java.lang.RuntimePermission.

The solution has no impact on the debugger APIs (JVM TI StopThread, JDWP ThreadReference/Stop, and JDI ThreadReference.stop). The debugger APIs can still be used to send an asynchronous exception as before.


Specification
-------------

A zip file with the specdiffs is attached to this CSR.

Asynchronous exceptions are described in JLS 11.1.3 and JVMS 2.10. A separate issue tracks the updates to the JLS and JVMS.



Comments
Moving to Approved. I left a comment on the PR suggesting using an implSpec tag; if you decided to make that edit, consider the CSR still approved, just update it afterward.
22-09-2022

The discussion on the PR related to special handling of ThreadDeath (TD) in JDK code. There are ~500 places that catch Throwable but do not special case TD. There are 13 place that special case TD. A developer using a debugger can cause any thread to throw any throwable at any time. If they use this feature to throw TD and so may observe a behavior change when compared to previous JDK releases. While possible, we don't think this is something to be concerned about. The more general observation is that the TD has a public constructor and so could be thrown explicitly. The JDK will no longer special cases but we didn't find anything release note worthy. Stuart has suggested that the release note just document that the JDK no longer special cases this error.
21-09-2022

Moving to Provisional, not Approved per on-going discussion on the PR.
20-09-2022