Re: [JGIT PATCH 11/12] Cleanup Config's MAGIC_EMPTY_VALUE to be more safe
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Jul 21, 2009, 21:54 UTC
- Message-ID
- <20090721215451.GU11191@spearce.org>
- In-Reply-To
- <200907212351.21760.robin.rosenberg@dewire.com>
Robin Rosenberg <robin.rosenberg@dewire.com> wrote:
> tisdag 21 juli 2009 22:19:29 skrev "Shawn O. Pearce" <spearce@spearce.org>: > > The magic value "%%magic%%empty%%" is just too magic;
...
Show 6 quoted lines
> > - 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.