Skip to content

Merge --lines ranges that overlap instead of rejecting them - #71

Merged
abashev merged 1 commit into
mainfrom
overlapping-lines-ranges
Sep 25, 2026
Merged

abashev merged 1 commit into
mainfrom
overlapping-lines-ranges

Conversation

@abashev

@abashev abashev commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Brings over google/google-java-format#1093, a fix from google-java-format 1.22.

The bug

open-java-format --lines=1:5 --lines=3:8 - < Foo.java
Overlapping ranges not permitted but found [0..5) overlapping [2..8)

followed by the usage text and exit code 2. The ranges were collected in an ImmutableRangeSet.Builder, which refuses overlapping and even adjacent ranges, so a caller that computes ranges from a diff had to merge them itself, and the same line given twice was an error.

From upstream, with the author kept

Added here

  • repeatedLines replaces the test that expected -lines=1:1 -lines=1:1 to be rejected.

Checked

  • Both tests fail on main and pass with the change; --lines=1:5 --lines=3:8 on the command line formats lines 1 to 8 and leaves the rest alone.
  • ./gradlew :open-java-format:test on JDK 21: 1498 tests, all green.
  • Formatting is untouched: the JDK corpus check does not apply to a command line option.

"--lines=1:5 --lines=3:8" failed with "Overlapping ranges not
permitted but found [0..5) overlapping [2..8)" and printed the usage
text. The ranges were collected in an ImmutableRangeSet.Builder, which
refuses overlapping and even adjacent ranges, so a caller that
computes ranges from a diff had to merge them itself, and the same
line given twice was an error.

This ports google/google-java-format#1093: the ranges are collected in
a TreeRangeSet, which merges them, and the usage text says that 1:5
means the first five lines. The mergedLines test comes from upstream;
repeatedLines replaces the test that expected the rejection.
@abashev
abashev merged commit 4978dca into main Sep 25, 2026
15 checks passed
@abashev
abashev deleted the overlapping-lines-ranges branch September 25, 2026 08:20
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