RFR 8206123 : ArrayDeque created with default constructor can only hold 15 elements

Martin Buchholz martinrb at google.com
Wed Jul 4 06:40:32 UTC 2018


On Tue, Jul 3, 2018 at 9:31 PM, Ivan Gerasimov <ivan.gerasimov at oracle.com>
wrote:

> Hi Martin!
>
> Why did you exclude the case of zero initial capacity?
>   96         int initialCapacity = rnd.nextInt(1, 20);
>
>
Well spotted - I was just being lazy - ArrayDeque doesn't handle the case
of zero specially.

     public void shouldNotResizeWhenInitialCapacityProvided() {
-        int initialCapacity = rnd.nextInt(1, 20);
+        int initialCapacity = rnd.nextInt(20);



> I think it may make sense to have "static final EMPTY_DEQUE =
> ArrayDeque(0);" somewhere, and we may want to make sure it doesn't allocate
> more memory than needed?
>
> It's perfectly fine to have this test:
>  149         assertTrue((head == tail) ^ (elements[head] != null));
>
>
I read ^ as "exactly one of these is true"
OTOH maybe I'm a serial abuser of the ^ operator - I've used it 7 times in
a single expression!


More information about the core-libs-dev mailing list