Skip to content

Make rotate a no-op on an empty range. - #8783

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1004859613
Oct 24, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1004859613

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Make rotate a no-op on an empty range.

rotate(array, distance, fromIndex, toIndex) computed length and -distance % length without guarding an empty range, so a call with fromIndex == toIndex threw ArithmeticException. Return early when the range has fewer than two elements.

Fixes #8772
Fixes #8774

RELNOTES=primitives: Fixed ArithmeticException when calling rotate on an empty subrange of a multi-element array.

`rotate(array, distance, fromIndex, toIndex)` computed `length` and `-distance % length` without guarding an empty range, so a call with `fromIndex == toIndex` threw `ArithmeticException`. Return early when the range has fewer than two elements.

Fixes #8772
Fixes #8774

RELNOTES=`primitives`: Fixed `ArithmeticException` when calling `rotate` on an empty subrange of a multi-element array.
PiperOrigin-RevId: 1006325060
@copybara-service
copybara-service Bot merged commit 5ae56d7 into master Oct 24, 2026
3 checks passed
@copybara-service
copybara-service Bot deleted the test_1004859613 branch October 24, 2026 16:23
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