4 ms·
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
by vivaamerica1 9y ago
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...
[0] https://stackoverflow.com/questions/11306032/please-explain-initialization-safety-as-spelled-out-in-java-memory-model https://stackoverflow.com/questions/11306032/please-explain-...