Skip to content

Drop trailing tabs from comments instead of writing them out - #73

Merged
abashev merged 1 commit into
mainfrom
trailing-tabs-in-comments
Sep 25, 2026
Merged

abashev merged 1 commit into
mainfrom
trailing-tabs-in-comments

Conversation

@abashev

@abashev abashev commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Brings over google/google-java-format#423 by Alexander Eckert, which fixes google/google-java-format#422 (google-java-format 1.8).

The bug

A line comment that ended in tabs, // comment\t\t\t, kept them in the output, so the formatted file had trailing whitespace where the same comment ending in spaces had none. JavaOutput collected pending spaces in a counter and wrote them only in front of the next non-blank character, which is what drops trailing spaces; a tab fell through to the default case and was written straight away.

From upstream, with the author kept

Checked

  • The test fails on main and passes with the change.
  • ./gradlew :open-java-format:test on JDK 21: 1498 tests, all green.
  • The 15,747 files of the JDK 21 sources format exactly as before: none of them has a comment ending in a tab.

A line comment that ended in tabs, "// comment\t\t\t", kept them in
the output, so the formatted file had trailing whitespace where the
same comment ending in spaces had none. JavaOutput collected pending
spaces in a counter and wrote them only in front of the next non-blank
character, which is what drops trailing spaces; a tab fell through to
the default case and was written straight away.

This ports google/google-java-format#423 by Alexander Eckert (upstream
commit 05f57ec9, fixing google/google-java-format#422): pending
whitespace is kept as text, tabs included, and written out only when
something follows it on the line, so a tab inside a comment stays and a
tab at the end of one goes. The removeTrailingTabsInComments test comes
from upstream, in this project's style.

The 15,747 files of the JDK 21 sources format exactly as before.
@abashev
abashev merged commit 8cc4259 into main Sep 25, 2026
15 checks passed
@abashev
abashev deleted the trailing-tabs-in-comments branch September 25, 2026 07:58
abashev added a commit to openjavaformat/docs that referenced this pull request Sep 25, 2026
…ange

2.98.0.4 carries two more fixes that change code palantir-java-format
2.98.0 has already formatted: a one-letter class name such as Android's
R no longer counts as a constant in a dotted name
(openjavaformat/open-java-format#70), and tabs at the end of a line in a
comment are dropped (openjavaformat/open-java-format#73). Neither shows
on the JDK 21 sources, which have no such dotted name and no comment
ending in a tab, and the corpus paragraph now says so. The other fixes
of 2.98.0.4 leave code that palantir-java-format has already formatted
as it is, so they stay off the list.

Every item now links the pull request behind it. The string fix went to
main without one, so it links the issue it closed,
openjavaformat/open-java-format#32.

The GitHub Action page gives 2.98.0.4 as the default of the version
input, as the action's main branch now does
(openjavaformat/open-java-format-action@83d0df8).
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.

Handling of trailing tabs in comments not idempotent

2 participants