Code review request for 6992121: StringBuilder.ensureCapacity(int minCap) throws OutOfMemoryError
David Holmes
David.Holmes at oracle.com
Mon Oct 18 23:54:10 UTC 2010
Hi Mandy,
The functional changes seem ok. However the ArrayList test is not right
because it checks the size not the capacity. The same with the Vector
test, though at least with Vector you can check capacity().
I find it odd that ArrayList has a very well defined notion of capacity
yet no method to query that capacity.
David
Mandy Chung said the following on 10/19/10 08:41:
> 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