Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

Martin Buchholz martinrb at google.com
Tue Mar 9 19:18:32 UTC 2010


On Tue, Mar 9, 2010 at 03:59, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
> In PriorityQueue:
>
> let's result newCapacity in 0xFFFF.FFFC  =-4
> then "if (newCapacity - MAX_ARRAY_SIZE > 0)" ---> false
> then Arrays.copyOf(queue, newCapacity) ---> ArrayIndexOutOfBoundsException

How could newCapacity ever become -4?
Since growth is by 50%.  But even 100% looks safe...

> Am I wrong ?
>
> 2.) Why don't you prefer a system-wide constant for MAX_ARRAY_SIZE ???

This should never become a public API - it's a bug in the VM.

I prefer the duplication of code to creating a new external dependency.

Martin

> -Ulf



More information about the core-libs-dev mailing list