RFR: 6206780 (str) Forwarding append methods in String{Buffer, Builder} are inconsistent

Alan Bateman Alan.Bateman at oracle.com
Tue Oct 2 09:07:45 UTC 2012

On 01/10/2012 22:22, Jim Gish wrote:
> Alan & Chris,
> I agree with you that the new approach is less clear than the previous 
> approach, but the original approach suffered from code duplication 
> which was the motivation for the change.  However, let me propose 
> something else.  How about /all /the methods in StringBuffer be 
> synchronized?  Although this is not strictly necessary, it works 
> because reentrant synchronization is allowed.  This eliminates the 
> original problem with code duplication with the dispatch during the 
> narrowing of types being done in both StringBuilder and StringBuffer, 
> and also eliminates the confusion about where synchronization is being 
> done and having to test for it.
> I can still add a test to ensure that all methods of StringBuffer are 
> synchronized, but that now becomes far easier - I simply can use 
> reflection on each method and test for isSynchronized().  Having to do 
> invocation tests to check for blocking or not seems much harder 
> (unless you have a trick in your bag that I don't yet know).
> Sound reasonable?
As Martin said, it's not free.

I think a comment (along the lines of the comments that you removed) 
would be sufficient to make it clear where the synchronization is done. 
Alternatively we just close this issue as it's not worth spending a lot 
of time on it.


More information about the core-libs-dev mailing list