4 ms·
> And as an aside to the aside: Check out this race condition that Wouter Coekaerts found in the String(char[]) constructor as a result of this optimization. Q
by josefx 3y ago
> And as an aside to the aside: Check out this race condition that Wouter Coekaerts found in the String(char[]) constructor as a result of this optimization.
Quite sure neither the char array nor the String constructor pretend to be thread safe and messing with the input of a constructor in parallel would break most java code in existence in weird and unexpected ways.
- distract8901 3y agoYeah, I'd expect that almost any code would react badly to modifying a ctor argument in parallel. That seems like a very bad thing to do in general.
- deleted 3y ago[deleted]
- dzaima 3y agoThe linked problem goes far past the result object being unstable though - namely, with it you can affect any string in any class file that the JVM loads in the future. That is, you can get yourself into a situation where the following function returns false: boolean foo() { System.out.println("hello world".startsWith("hello")); }