Java 25 parser: don't merge /// blocks across blank lines#7556
Merged
Java 25 parser: don't merge /// blocks across blank lines#7556
/// blocks across blank lines#7556Conversation
Per JEP 467, a blank line terminates a markdown doc comment, so two `///` blocks separated by an empty line are distinct doc comments. The merging code in `formatWithMarkdownJavaDoc` previously walked backward across all consecutive `///` lines without checking the inter-comment suffix, which interleaved their characters when re-printed. Found while running `FindParseFailures` against `JabRef/jabref` for #7554.
346841d to
27b7e77
Compare
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.
Summary
Per JEP 467, a blank line terminates a markdown doc comment, so two
///blocks separated by an empty line are distinct doc comments. The merging logic informatWithMarkdownJavaDocpreviously walked backward through every consecutive///line without checking the inter-comment suffix, which scrambled the contents when the source was re-printed.Reproducer (now covered by a TCK test):
Before the fix, the source round-tripped to:
The fix is small: when walking the consecutive-
///run backward, break when the previous comment's suffix contains more than one newline (i.e. a blank line gap).FindParseFailuresagainstJabRef/jabreffor "There were problems parsing" should show line number and/or excerpt of source code #7554. The varargs/@formatter:offcase from that same analysis is already covered by Fix Java parser for annotated varargs by adding marker onJ.ArrayType, as opposed to field onJ.VariableDeclarations#6098, so this PR only addresses the markdown-doc-comment regression.Test plan
JavadocTest.MarkdownDocComment.twoTripleSlashBlocksSeparatedByBlankLinefails before the fix and passes after.:rewrite-java-25:compatibilityTestsuite still green.