Java's TypeVariable.getBounds is not thread safe
vmlens.com
vmlens.com
[1] See https://bartoszmilewski.com/2008/11/05/who-ordered-memory-fe... for a readable discussion about what x86/x64 does and doesn't do.
System.out.println(System.identityHashCode(java.util.List.class.getTypeParameters()[0]));
System.out.println(System.identityHashCode(java.util.List.class.getTypeParameters()[0]));
2018699554
2018699554Another great failure is UUID.generateRandomUUID(); One would think that's thread safe... [maybe it's fixed now]
"A class that represents an immutable universally unique identifier (UUID). A UUID represents a 128-bit value."
Looks thread safe to me. No setters on the object.
I hope this has been fixed in subsequent releases!
So I'd think it only matters if `volatile` doesn't guarantee that non-final object fields are fully initialized... and I can't find anything that explicitly states one way or another, so I'm not sure. If it doesn't make that guarantee, then yeah - this could publish a partly-initialized SecureRandom without a generator, which would probably crash. But the contents of https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.htm... imply to me that write-then-read is equivalent to a synchronized block or any other monitor sequence (and in the method they only use the local var, so it doesn't matter for the creator-thread), so I suspect it's fine. Just can't claim any further.
@exabrial: care to elaborate? What's unsafe / have you seen crashes due to uninitialized SecureRandom?
EDIT: In this case numberGenerator is volatile so it introduces happens-before relations between write and read.
I think it's reasonable to assume that any documented API must at least be callable.
[1] The JDK documentation is pretty good on spelling out such caveats, IME.
Java's raison d'être was arguably the byte code verifier. Being able to crash the JVM with validated byte code is always a bug.
* the code is very abstract and touches a lot of classes so there could be some unsafe code hiding there i can't see.
SimpleDateFormat YMD = new SimpleDateFormat("yyyy-MM-dd");
If you call YMD.parse() from multiple threads, it will sometimes return the wrong date. Cleaning up the database after that bug was loads of fun.Oh wait, they're Java programmers. ;p