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.

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

Commit messages:
 - [PATCH] Read volatile field uncaughtExceptionHandler only once to avoid race

Changes: https://git.openjdk.java.net/jdk/pull/7117/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=7117&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8280174
  Stats: 3 lines in 1 file changed: 0 ins; 0 del; 3 mod
  Patch: https://git.openjdk.java.net/jdk/pull/7117.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/7117/head:pull/7117

PR: https://git.openjdk.java.net/jdk/pull/7117

Reply via email to