Stop breaking line comments at a no-break space - #41
Merged
Merged
Conversation
JavaCommentsHelper wraps a line comment that is too long at the last whitespace before the limit, and CharMatcher.whitespace() counts the no-break space U+00A0 as whitespace. The continuation line then starts with "//" and that no-break space. LINE_COMMENT_MISSING_SPACE_PREFIX, whose \s does not match it, takes that for a comment with no space after the slashes, so the next run pads it, breaks at the no-break space again and leaves the padding behind as an empty "//" line. Every run adds one, and the file never settles (#38, from google/google-java-format#562). Line comments now break only at breaking whitespace, which leaves out U+00A0, U+2007 and U+202F: a no-break space is by definition not a place to break a line. A number grouped with no-break spaces now moves to the next line whole instead of being cut inside. The new golden covers both shapes. The 15,747 files of the JDK 21 sources format exactly as before; none of them contains a no-break space.
abashev
enabled auto-merge
September 23, 2026 07:24
abashev
disabled auto-merge
September 23, 2026 08:00
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.
Closes #38. Upstream report: google/google-java-format#562.
What changes
JavaCommentsHelper.wrapLineCommentsbreaks a line comment that is too long only at breaking whitespace,CharMatcher.breakingWhitespace(), and no longer at a no-break space (U+00A0, U+2007, U+202F). Breaking there left a continuation line that starts with//and the no-break space. The next run took that for a missing space, padded it, broke at the no-break space again and left an empty//line behind, one more on every run.A number grouped with no-break spaces, such as
1 000 000, now moves to the next line whole instead of being cut inside.Checked
ojf-issue-38-nbsp-line-commentfails without the change (the comment is cut before each no-break space) and passes with it. It covers a number grouped with no-break spaces and the shape from Running with --replace does not converge google/google-java-format#562../gradlew :open-java-format:teston JDK 21: 1421 tests, all green.