Hello.
I see that Thread.dispatchUncaughtException calls
getUncaughtExceptionHandler() which reads volatile field twice:
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/Thread.java#L1978

private volatile UncaughtExceptionHandler uncaughtExceptionHandler;

public UncaughtExceptionHandler getUncaughtExceptionHandler() {
    return uncaughtExceptionHandler != null ?
        uncaughtExceptionHandler : group;
}

private void dispatchUncaughtException(Throwable e) {
    getUncaughtExceptionHandler().uncaughtException(this, e);
}


I wonder if it's possible to get a NPE here? Another thread could
change uncaughtExceptionHandler between 2 volatile reads.
Or JVM somehow forbid this?




Andrey Turbanov

Reply via email to