Code review request for 6992121: StringBuilder.ensureCapacity(int minCap) throws OutOfMemoryError
Mandy Chung
mandy.chung at oracle.com
Mon Oct 18 22:41:43 UTC 2010
Please review the fix for:
6992121: StringBuilder.ensureCapacity(int minCap) throws
OutOfMemoryError with minCap=Integer.MIN_VALUE
Webrev at:
http://cr.openjdk.java.net/~mchung/6992121/webrev.00/
This is a regression caused by the changes for 6933217 (Huge arrays
handled poorly in core libraries). The ensureCapacity() method in the
StringBuffer, StringBuilder, ArrayList, and Vector classes are a public
API that accepts negative numbers. The following overflow-conscious code:
if (minimumCapacity - value.length> 0)
considers negative minimumCapacity as overflow case where OutOfMemoryError will be thrown. So the implementation of the public ensureCapacity() methods need to check if the input argument is positive before doing the above overflow-conscious check.
Thanks
Mandy
More information about the core-libs-dev
mailing list