Skip to content

Java 25 parser: don't merge /// blocks across blank lines#7556

Merged
timtebeek merged 2 commits intomainfrom
tim/java-parser-jabref-fixes
May 4, 2026
Merged

Java 25 parser: don't merge /// blocks across blank lines#7556
timtebeek merged 2 commits intomainfrom
tim/java-parser-jabref-fixes

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 3, 2026

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 in formatWithMarkdownJavaDoc previously 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):

/// First doc-comment block.

/// Second doc-comment block.
class Test {}

Before the fix, the source round-tripped to:

/// Secon d doc-comme nt blo
///ck.cond doc-comment block.
class Test {}

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).

Test plan

  • New TCK test JavadocTest.MarkdownDocComment.twoTripleSlashBlocksSeparatedByBlankLine fails before the fix and passes after.
  • Full :rewrite-java-25:compatibilityTest suite still green.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 3, 2026
@timtebeek timtebeek marked this pull request as ready for review May 3, 2026 21:30
@timtebeek timtebeek requested a review from greg-at-moderne May 3, 2026 21:30
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.
@timtebeek timtebeek merged commit 2a9e9f8 into main May 4, 2026
1 check passed
@timtebeek timtebeek deleted the tim/java-parser-jabref-fixes branch May 4, 2026 18:49
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant