Fix print idempotency for Javadoc <pre><code> blocks on Java 25#7464
Merged
knutwannheden merged 1 commit intomainfrom Apr 23, 2026
Merged
Fix print idempotency for Javadoc <pre><code> blocks on Java 25#7464knutwannheden merged 1 commit intomainfrom
<pre><code> blocks on Java 25#7464knutwannheden merged 1 commit intomainfrom
Conversation
Java 25's `DocCommentTree` strips leading whitespace (including newlines) from text nodes, so the source string had a `\n` that the `DCText` body didn't. `visitText` silently advanced past it without emitting a `LineBreak`, and the orphaned line break was flushed at the end of the comment as a stray ` *` line. Consume any source newline that's missing from the text node before processing each character, emitting the corresponding `LineBreak`.
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.
Motivation
Parsing Javadoc comments containing
<pre><code>blocks with a newline after the opening tag failed the parser's print idempotency check on Java 25 (but not on Java 8/11/17/21). This surfaced against Google Dagger in a Moderne CLI run — 18 Java files ingoogle/daggerfailed to parse withIllegalStateException: ... is not print idempotent, all of them Javadoc comments in the common style:Root cause: Java 25's
DocCommentTreestrips leading whitespace (including newlines) from text nodes, so the raw source has\ncharacters that theDCText/DCRawTextbody does not. InReloadableJava25JavadocVisitor.visitText, theelsebranch blindly advanced the cursor past these\ncharacters without emitting a correspondingLineBreak. The unconsumedLineBreakthen got dumped at the end of the comment by the trailing-lineBreaks flush, producing a stray*line before the closing*/.Summary
ReloadableJava25JavadocVisitor.visitText: before processing each character from the text node, consume any\nin the source that is missing from the node and emit the correspondingLineBreak.JavadocTestcovering variants of<pre><code>blocks (newline after opening tag, two consecutive blocks, blocks containing{@literal}inline tags, block starting on the same line as preceding text).Test plan
./gradlew :rewrite-java-25:test :rewrite-java-25:compatibilityTest— all green, including the four newpreCodeBlock*tests