On Mon, 17 Jan 2022 20:56:56 GMT, Andrey Turbanov <aturba...@openjdk.org> wrote:
> Method `Thread.dispatchUncaughtException` (called by VM) uses result of of > `getUncaughtExceptionHandler`. Field `uncaughtExceptionHandler` is volatile > and can be changed by another Thread. Which could lead to NPE. > https://github.com/openjdk/jdk/blob/7b6738fa02023825ed9e602555bd5ed2b87a6ca6/src/java.base/share/classes/java/lang/Thread.java#L2007-L2009 > Read field to local variable to avoid double volatile read. This looks okay. It is arguably an API bug that the UHE can be changed after another Thread after it has been started but too late to change that now. Should be rare to change another Thread's UHE to null but a bug none the less. ------------- Marked as reviewed by alanb (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/7117