JDK-8232654 : Degrade Thread.countStackFrames() to throw UOE
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 14
  • Submitted: 2019-10-19
  • Updated: 2019-10-30
  • Resolved: 2019-10-30
Related Reports
CSR :  
Description
Summary
-------

Re-specify `Thread::countStackFrames` to unconditionally throw `UnsupportedOperationException` in advance of removing the method in a future release. The method has been deprecated since Java SE 1.2, and deprecated for removal since Java SE 9.

Problem
-------

This method has always been ill-defined and useless. It requires the target thread to be suspended, an operation that is inherently deadlock prone. The `StackWalker` API has provided a better solution for stack walking needs since Java SE 9.

Solution
--------

Re-specify `Thread::countStackFrames` to unconditionally throw `UnsupportedOperationException`.

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

Change specification to:

```
    /**
     * Throws {@code UnsupportedOperationException}.
     *
     * @return     nothing
     *
     * @deprecated This method was originally designed to count the number of
     *             stack frames but the results were never well-defined and it
     *             depended on thread-suspension.
     *             This method is subject to removal in a future version of Java SE.
     * @see        StackWalker
     */
```


Comments
Moving to Approved.
30-10-2019

Ok ! Thanks Alan
29-10-2019

UnsupportedOperationException is widely used in Java SE in contexts that are not collections (hundreds of examples in the JDK now). We agreed in JDK 8 that to use it for Thread.stop(Throwable).
29-10-2019

Why not throw NoSuchMethodError instead of UnsupportedOperationException as Thread::destroy has done in the past ? UnsupportedOperationException is defined by the collection API so IMO less suitable in this context.
29-10-2019