Possible NPE in Thread.dispatchUncaughtException

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 19
    • Affects Version/s: 17, 18, 19
    • Component/s: core-libs
    • b07

      Thread.dispatchUncaughtException calls getUncaughtExceptionHandler() which reads volatile field twice:

          private volatile UncaughtExceptionHandler uncaughtExceptionHandler;

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

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

      Another thread could change uncaughtExceptionHandler between 2 volatile reads. It will result in NullPointerException

            Assignee:
            Andrey Turbanov
            Reporter:
            Andrey Turbanov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: