Subject: Re: [JGIT PATCH 11/12] Cleanup Config's MAGIC_EMPTY_VALUE to be more safe

From: "Shawn O. Pearce" <[email-masked]>
Date: Tue, 21 Jul 2009 14:54:51 -0700

Robin Rosenberg <[email-masked]> wrote:
> tisdag 21 juli 2009 22:19:29 skrev "Shawn O. Pearce" <[email-masked]>:
> > The magic value "%%magic%%empty%%" is just too magic; 
...
> > -	private static final String MAGIC_EMPTY_VALUE = "%%magic%%empty%%";
> > +	private static final String MAGIC_EMPTY_VALUE = new StringBuilder(0)
> > +			.toString();
> 
> Can we be sure an implementation doesn't "optimize" toString() here? But an
> explicit new String() shouldn't be..?

*sigh*

I used this form because FindBugs dislikes new String("").  But yea,
at least with new String() we know its a new string object and
there is no pooling of the empty string going on under the covers.

I can't imagine it being a common enough case to convert a
StringBuilder to an empty string that a runtime implementation would
waste instructions over checking for it and reusing a pooled copy,
but eh, yea, maybe this should be new String("") and include a
FindBugs entry to disable the warning here.

-- 
Shawn.