Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8261404

Class.getReflectionFactory() is not thread-safe

XMLWordPrintable

    • b03
    • generic
    • generic
    • Verified

        A DESCRIPTION OF THE PROBLEM :
        The private method `java.lang.Class.getReflectionFactory()` appears to not be thread-safe.
        It lazily initializes the `reflectionFactory` field but there is no happens-before relationship. Therefore it is allowed by the Java Memory Model that the first read of the `reflectionFactory` reads a non-null value and the second read (as part of the `return`) statement returns null, causing a NullPointerException for the caller.

        See also https://shipilev.net/blog/2016/close-encounters-of-jmm-kind/#wishful-benign-is-resilient


              darcy Joe Darcy
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: