Skip to content

[COLLECTIONS-901] Avoid overflow in final ListUtils partition - #751

Open
AryanRG wants to merge 1 commit into
apache:masterfrom
AryanRG:COLLECTIONS-901-partition-overflow
Open

AryanRG wants to merge 1 commit into
apache:masterfrom
AryanRG:COLLECTIONS-901-partition-overflow

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 18, 2026

Copy link
Copy Markdown

Summary

  • Bound the end of the final ListUtils.partition() slice using the remaining element count. The previous start + size could overflow before Math.min.
  • Add a virtual Integer.MAX_VALUE-element list test, so the failing case needs no large allocation.
  • Link the fix to the next release notes.

Jira: https://issues.apache.org/jira/browse/COLLECTIONS-901

This is separate from COLLECTIONS-673, which fixed overflow in Partition.size(); this failure is in Partition.get().

Validation

  • The new test fails on unmodified master with fromIndex(1073741825) > toIndex(-2147483646) and passes with this change. The exact code diff passed independent review; ListUtilsTest ran 28 tests without failure.
  • The default Maven goal passed on the final three-file commit with mvn -q on macOS/JDK 27. xmllint --noout src/changes/changes.xml and git diff --check passed.
  • Hosted CI is pending.

AI assistance

Kiro with Claude Opus 5.5 assisted with the initial code and regression test. A separate Kiro review checked the exact code diff and independently reproduced the failure before and success after the fix.

Checklist

  • Read this project's contribution guidelines.
  • Read the ASF Generative Tooling Guidance.
  • Disclosed the AI tool and extent of assistance above.
  • Ran the default Maven goal successfully.
  • Added a regression test that fails without the runtime change.
  • Explained the change, reason, and validation.
  • Used a meaningful Jira-keyed commit subject and body.

Compute the final sublist end from the remaining element count instead of adding the partition size before bounding it. Add a virtual large-list regression that fails before the fix.
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.

1 participant