RFR: 8318839: Update test thread factory to catch all exceptions

David Holmes dholmes at openjdk.org
Fri Oct 27 05:58:33 UTC 2023


On Thu, 26 Oct 2023 22:34:24 GMT, Leonid Mesnik <lmesnik at openjdk.org> wrote:

>> test/jtreg_test_thread_factory/src/share/classes/Virtual.java line 37:
>> 
>>> 35:             // The virtual threads don't belong to any group and need global handler.
>>> 36:             Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
>>> 37:                     if (e instanceof ThreadDeath) {
>> 
>> `ThreadDeath` has been deprecated for removal since Java 20, so this should no longer be needed.
>
> It is still used in tests and we should ignore it like jtreg doing.

Shouldn't this code first retrieve the current default exception handler, and then check whether t is a virtual thread, and if so handle the exception as appropriate (not sure System.exit is appropriate ..). Then for non-virtual threads it delegates to the previous default handler.

final UncaughtExceptionHandler originalUEH = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
        if (t.isVirtual()) {
            // ...
        } else {
            originalUEH.uncaughtException(t, e);
        }
});

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16369#discussion_r1374102902


More information about the core-libs-dev mailing list