ertugrulcetin / GlueList

GlueList is brand new list implementation which is faster than classic List implementations
169 stars 17 forks source link

Off by one? #1

Closed dstarh closed 8 years ago

dstarh commented 8 years ago

Am I crazy or is there an off by one error here?

    private void rangeCheckForAdd(int index) {

        if (index > size || index < 0) {
            throw new ArrayIndexOutOfBoundsException(index);
        }
    }

A list of size 1 does not have anything at index 1

ertugrulcetin commented 8 years ago

@dstarh Nope there is no problem at all. It's dynamically growing(just like ArrayList) so the expression index > size is valid.

If you look ArrayList source code, you will see this following method:

    /**
     * A version of rangeCheck used by add and addAll.
     */

 private void rangeCheckForAdd(int index) {
        if (index > size || index < 0)
            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
    }