RFR: 8376568: Change Thread::getStackTrace to use handshake op for all cases [v2]

David Holmes dholmes at openjdk.org
Fri Jan 30 04:50:26 UTC 2026


On Thu, 29 Jan 2026 09:01:20 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Thread.java line 2218:
>> 
>>> 2216:             }
>>> 2217:             Object trace = getStackTrace0();
>>> 2218:             if (trace instanceof StackTraceElement[] stackTrace) {
>> 
>> What can this return other than a `StackTraceElement[]` ??
>
> It can only return a StackTraceElement[] or null. Using a type pattern seemed nicer here to avoid a null check + explicit cast.

Sorry I have to disagree - a type check screams to me that this could be some other type when it can't. A null check would be better IMO.

On the matter of the cast, why doesn't getStackTrace0 return STE[] instead of object?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29461#discussion_r2744587005


More information about the core-libs-dev mailing list