Skip to content

Conversation

@meetgoti07
Copy link

When using range notation in API pagination (e.g., tree=jobs[name]{11000,12000}), if the fromIndex exceeds the actual collection size, Range.apply() previously caused List.subList() to throw IllegalArgumentException: fromIndex > toIndex.

This fix adds a bounds check before calling subList(min, s.size()). When min >= s.size(), the method now returns an empty list instead of throwing.

This allows Jenkins API clients to paginate beyond the end of a collection and receive an empty result, which is the expected behavior when iterating through pages of data.

Testing done

  • Added 2 new test cases in RangeTest.java:
    • rangeBeyondListSizeReturnsEmpty() - verifies empty result when range starts beyond collection size
    • rangeExactlyAtBoundaryReturnsEmpty() - verifies empty result when min equals collection size
  • All 5 tests in RangeTest pass
  • Tested with arrays, Lists, and Sets to ensure consistent behavior

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

When using range notation in API pagination (e.g., tree=jobs[name]{11000,12000}),
if the fromIndex exceeds the actual collection size, Range.apply() previously
caused List.subList() to throw IllegalArgumentException: fromIndex > toIndex.

This fix adds a bounds check before calling subList(min, s.size()). When
min >= s.size(), the method now returns an empty list instead of throwing.

This allows Jenkins API clients to paginate beyond the end of a collection
and receive an empty result, which is the expected behavior when iterating
through pages of data.
@meetgoti07
Copy link
Author

@timja I have made the requested changes. Please review at your convenience. Thank you.

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.

2 participants