RFR: 8149330: Capacity of StringBuilder should not get close to Integer.MAX_VALUE unless necessary

Martin Buchholz martinrb at google.com
Tue Feb 23 17:29:40 UTC 2016

On Tue, Feb 23, 2016 at 7:20 AM, Ivan Gerasimov
<ivan.gerasimov at oracle.com> wrote:
> While writing this, I just noticed that I actually made a mistake when did
> newCapacity < 0 check.
> This wouldn't catch the overflow when the oldCapacity happens to be
> Integer.MAX_VALUE (which is not possible with the current hotspot, but may
> become an issue one day).

Well done!

One interesting way that capacity may end up being Integer.MAX_VALUE
is if we switch to char[] for storage.  Then in LATIN1 mode you could
store Integer.MAX_VALUE elements even without help from hotspot!

More information about the core-libs-dev mailing list