IndexTreeList java.lang.IndexOutOfBoundsException calling addFirst(E e) on an empty list

Open Beginner friendly
#1,059 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
java, kotlin
Domain
database

Research direction

Search for IndexTreeList and its checkIndex(index: Int) method, then trace addFirst(E e) on an empty list. Verify the insertion boundary against the Java add contract, and confirm that addFirst succeeds when size is zero while invalid indexes still fail.

Written by the indexing model from the issue text.

Description

Issue Summary: The method checkIndex(index: Int) in the class IndexTreeList (version 3.1.0) appears to enforce an index boundary check that aligns with the contract for AbstractList.set(index, element), but not with that of add(E e) or addFirst(E e).

Code Reference:

fun checkIndex(index: Int) {
    if (index < 0 || index >= size)
        throw IndexOutOfBoundsException()
}

According to the Java documentation, the index validation for add(int index, E element) (and by extension for similar insertion methods such as addFirst(E e)) should be:

IndexOutOfBoundsException – if the index is out of range (index < 0 || index > size())

The issue manifests when calling addFirst(E e) on an empty IndexTreeList. Internally, this results in a call to checkIndex(0), which throws IndexOutOfBoundsException, even though 0 is a valid index for insertion into an empty list (where size == 0).

Dominant language
Java
Stars
5.1k
Forks
877
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jankotek/mapdb

All issues in jankotek/mapdb

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.