A DESCRIPTION OF THE PROBLEM :
The invoke method of LocalExecutionControl from JShell replaces Thread.defaultUncaughtExceptionHandler unconditionally, and it also never sets it back.
This specially affects jdk.jshell API users that wish to use such ExecutionControl, and isn't documented anywhere.
Instead, given that method starts code in its own ThreadGroup, it should override the ThreadGroup's uncaughtException method, so other code isn't affected.
---------- BEGIN SOURCE ----------
Thread.UncaughtExceptionHandler handler = (e, t) -> {};
Thread.setDefaultUncaughtExceptionHandler(handler);
try (JShell jshell = JShell.builder()
.executionEngine(new LocalExecutionControlProvider(), Map.of())
.build()) {
jshell.eval("0");
}
System.out.println(handler == Thread.getDefaultUncaughtExceptionHandler());
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Implementing an ExecutionControlProvider that returns an extension of LocalExecutionControl overriding invoke that captures the current one and sets it back after a call to super.invoke.
The (proper in my opinion) solution is instead, given that method starts code in its own ThreadGroup, to override the ThreadGroup's uncaughtException method.
FREQUENCY : always
The invoke method of LocalExecutionControl from JShell replaces Thread.defaultUncaughtExceptionHandler unconditionally, and it also never sets it back.
This specially affects jdk.jshell API users that wish to use such ExecutionControl, and isn't documented anywhere.
Instead, given that method starts code in its own ThreadGroup, it should override the ThreadGroup's uncaughtException method, so other code isn't affected.
---------- BEGIN SOURCE ----------
Thread.UncaughtExceptionHandler handler = (e, t) -> {};
Thread.setDefaultUncaughtExceptionHandler(handler);
try (JShell jshell = JShell.builder()
.executionEngine(new LocalExecutionControlProvider(), Map.of())
.build()) {
jshell.eval("0");
}
System.out.println(handler == Thread.getDefaultUncaughtExceptionHandler());
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Implementing an ExecutionControlProvider that returns an extension of LocalExecutionControl overriding invoke that captures the current one and sets it back after a call to super.invoke.
The (proper in my opinion) solution is instead, given that method starts code in its own ThreadGroup, to override the ThreadGroup's uncaughtException method.
FREQUENCY : always
- links to
-
Review openjdk/jdk/12982