Fix infinite loop in JumpSearch when key exceeds last element - #7555
Merged
alxkm merged 1 commit intoAug 5, 2026
Merged
Conversation
SEPURI-SAI-KRISHNA
requested review from
DenizAltunkapan,
alxkm and
yanglbme
as code owners
August 5, 2026 04:54
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7555 +/- ##
============================================
- Coverage 80.42% 80.41% -0.01%
+ Complexity 7457 7456 -1
============================================
Files 815 815
Lines 24055 24055
Branches 4732 4732
============================================
- Hits 19346 19345 -1
Misses 3945 3945
- Partials 764 765 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
alxkm
approved these changes
Aug 5, 2026
alxkm
left a comment
Member
There was a problem hiding this comment.
Looks good. Thank you for the contribution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JumpSearch.findnever terminates when the key is greater than the last element of the array.The jumping loop clamps its cursor to the last index:
Once
limitreacheslength - 1,Math.min(limit + blockSize, length - 1)evaluates back tolength - 1, so the cursor stops moving. If the key is still greater thanarray[length - 1], the loop condition stays true forever and the call hangs, burning CPU.Reproducer:
The clamp is unnecessary — the loop condition
limit < lengthalready stops the scan, and the linear-search loop that follows is bounded byi <= limit && i < length. Lettinglimitrun past the end restores termination without changing any other behaviour.Fix
limit = Math.min(limit + blockSize, length - 1);→limit += blockSize;Tests
testJumpSearchKeyGreaterThanLastElement— the minimal reproducer, with@Timeout(threadMode = SEPARATE_THREAD)so the hang surfaces as a failure instead of stalling CI.testJumpSearchKeyGreaterThanLastElementForEveryLength— same, for lengths 1–50, since the block size depends on the array length.testJumpSearchFindsEveryElement— every index of every array of length 1–50 is still found, covering the elements that sit exactly on a jump boundary.All three fail (time out) on
masterand pass with the fix. The existing tests never used a key above the maximum, which is why this went unnoticed.clang-format -i --style=file path/to/your/file.java