Re:Java.math.BigDecimal toString is not thread safe
by vivaamerica1 on Wednesday August 30, 2017 @10:25PM
(#15137724)
Agree with others that String.length() should never ever throw NPE from within String, regardless of it being called from whatever thread.
Now, in the comments there's another idea suggesting the unsafe publication of String (partially constructed). This would be the case if String.value wasn't final (essentially the case of double-checked locking). But that's not the case here because String.value is final[0]
While it's a JVM bug, making stringCache volatile would be one way to fix it - unless the JVM is also broken around volatile...
Now, in the comments there's another idea suggesting the unsafe publication of String (partially constructed). This would be the case if String.value wasn't final (essentially the case of double-checked locking). But that's not the case here because String.value is final[0]
While it's a JVM bug, making stringCache volatile would be one way to fix it - unless the JVM is also broken around volatile...
[0] https://stackoverflow.com/questions/11306032/please-explain-...