Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream
Kevin L. Stern
kevin.l.stern at gmail.com
Fri Mar 5 02:39:10 PST 2010
FYI, HashMap independently defines a MAXIMUM_CAPACITY variable; it might be
a good idea to retrofit this and other such local definitions with any
system wide variables that are defined.
* The maximum capacity, used if a higher value is implicitly specified
* by either of the constructors with arguments.
* MUST be a power of two <= 1<<30.
static final int MAXIMUM_CAPACITY = 1 << 30;
On Fri, Mar 5, 2010 at 4:06 AM, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
> Am 05.03.2010 10:04, schrieb Martin Buchholz:
> Hi Kevin,
>> As you've noticed, creating objects within a factor of two of
>> their natural limits is a good way to expose lurking bugs.
>> I'm the one responsible for the algorithm in ArrayList.
>> I'm a bit embarrassed, looking at that code today.
>> We could set the array size to Integer.MAX_VALUE,
>> but then you might hit an independent buglet in hotspot
>> that you cannot allocate an array with Integer.MAX_VALUE
>> elements, but Integer.MAX_VALUE - 5 (or so) works.
> I think, using a max size of Integer.MAX_VALUE - x looks awful, in
> particular if it's badly commented in the sources.
> I suggest to introduce something like System.MAX_COLLECTION_SIZE/CAPACITY
> or .maxCollectionSize/Capacity().
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the core-libs-dev