Skip to content

Comments

Fix #132: Throw on invalid index in getNode and insertNode#143

Open
gnodet wants to merge 1 commit intomainfrom
fix/132-getnode-bounds-check
Open

Fix #132: Throw on invalid index in getNode and insertNode#143
gnodet wants to merge 1 commit intomainfrom
fix/132-getnode-bounds-check

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Feb 21, 2026

Summary

  • Change getNode(int) to throw IndexOutOfBoundsException for out-of-range indices instead of returning null
  • Change insertNode(int, Node) to throw IndexOutOfBoundsException/IllegalArgumentException instead of silently ignoring invalid input
  • Matches standard Java collection behavior

BREAKING CHANGE: getNode(int) now throws instead of returning null. insertNode(int, Node) now throws instead of silently ignoring invalid input.

Test plan

  • Out-of-bounds index throws IndexOutOfBoundsException
  • Valid index access still works
  • All existing tests pass with new behavior

Closes #132

Change getNode(int) to throw IndexOutOfBoundsException for out-of-range
indices instead of silently returning null. Change insertNode(int, Node)
to throw IndexOutOfBoundsException/IllegalArgumentException instead of
silently ignoring invalid input. This matches standard Java collection
behavior and prevents hidden bugs.

BREAKING CHANGE: getNode(int) now throws IndexOutOfBoundsException instead
of returning null for invalid indices. insertNode(int, Node) now throws
instead of silently ignoring invalid input.
@github-actions
Copy link

✅ CI Build PASSED

Build Status: PASSED
Java Version: 21
Maven Command: ./mvnw verify

🎉 All tests passed! The build is ready for merge.

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.

ContainerNode.getNode(int) too forgiving

1 participant