Skip to content

Fix IndexTreeList.add(index) to allow index == size - #1067

Open
arimu1 wants to merge 1 commit into
jankotek:release-3.1from
arimu1:fix/index-tree-list-add-index-bounds
Open

arimu1 wants to merge 1 commit into
jankotek:release-3.1from
arimu1:fix/index-tree-list-add-index-bounds

Conversation

@arimu1

@arimu1 arimu1 commented Sep 3, 2026

Copy link
Copy Markdown

Fixes #1059

Problem

IndexTreeList.add(index, element) called checkIndex(index), which rejects index >= size. That matches access operations (get, set, removeAt) but not insertion: List.add(int, E) allows index == size() for append-style inserts. On an empty list, add(0, e) (and JDK 21 addFirst) therefore threw IndexOutOfBoundsException.

Fix

Use insertion bounds in add(index, element) only: index < 0 || index > size. Leave checkIndex unchanged for read/update/remove paths.

Testing

mvn test -Dtest=IndexTreeListTest#addAtIndexEmptyList,IndexTreeListTest#addAtIndexAppend -Dmdbtest=1

Result: 2 tests passed (darwin, Corretto 8 / Maven default JDK).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant