-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P3
-
Affects Version/s: 5.0
-
Component/s: core-libs
-
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.
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.