According to the GrepCode.com version of the source , it looks like this might be a mistake in their implementation.
The whole add function is a call
public boolean add(E e) { return offer(e); }
The offer function looks like this:
public boolean offer(E e) { if (e == null) throw new NullPointerException(); modCount++; int i = size; if (i >= queue.length) grow(i + 1); size = i + 1; if (i == 0) queue[0] = e; else siftUp(i, e); return true; }
You will notice that size = i + 1 is called before the element is actually inserted through siftUp. When siftUp is called, the very first thing it does is try to apply to Comparable and throw an exception before inserting the element. Therefore, it increases the size without actually inserting the element.
source share