thread safety of random number generator in UUID requires volatile field

XMLWordPrintable

    • b44
    • sparc
    • solaris_9

      customer writes:

      I was just idly looking through the source of 1.5.0 as one does and have
      seen something that looks as if it might fall foul of the same problem as
      double-locking, eg the possibility of seeing a partly constructed object.

      Specifically, in the new UUID class, the code has a static SecureRandom
      numberGenerator = null declaration, and then code that uses it is not
      synchronised and starts if(numberGenerator == null) { numberGenerator = new
      SecureRandom(); } ...use numberGenerator ... rather than doing something
      like SecureRandom myNG = numberGenerator; if(myNG == null) { numberGenerator
      = myNG = new SecureRandom(); } ... use myNG ... I don't care about the
      possibility of creating and discarding an extra generator, but rather about
      an a race with the assignment to numberGenerator by one thread becoming
      visible after the "if" in another thread.

            Assignee:
            Michael Mccloskey (Inactive)
            Reporter:
            Michael Mccloskey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: