classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [cp-patches] StringBuilder and Appendable for CVS HEAD


From: Jeroen Frijters
Subject: RE: [cp-patches] StringBuilder and Appendable for CVS HEAD
Date: Thu, 16 Dec 2004 08:32:59 +0100

address@hidden wrote:
> >>>>> "Jeroen" == Jeroen Frijters <address@hidden> writes:
> 
> Jeroen> The "shared" rubbish needs to be ripped out of 
> StringBuilder and the
> Jeroen> String(StringBuilder) constructor needs to make a 
> copy of the array.
> 
> I'm not so sure that the current code is unsafe.
> I don't think there is a path where a String's contents can change
> unexpectedly.

In the String(StringBuilder) constructor:

+            buffer.shared = true;
+            value = buffer.value;

Any of the StringBuilder methods that test "shared" and then go on to
modify the array can cause a string to be modified (Thread A constructs
a string that shares the array, meanwhile Thread B is operating on the
shared array).

(Additionally, since "shared" isn't volatile, Thread B doesn't even have
to see the write of thread A.)

Regards,
Jeroen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]