Java: realign Javadoc cursor when javac strips continuation whitespace#7531
Merged
Java: realign Javadoc cursor when javac strips continuation whitespace#7531
Conversation
Java 23+ javac's `DCText`/`DCComment` `getBody()` strips per-line leading whitespace that older versions preserved. The cleaned source still carries that whitespace, so when an older parser (e.g. `rewrite-java-21`) runs on a Java 25 JVM, `visitText` falls one character behind on every continuation line — dropping the `*`-margin trailing space and emitting a duplicated trailing char from the leftover-source branch in `visitDocComment`. After consuming a `\n`, advance the cursor over any source whitespace that the body lacks at the corresponding position. Mirrors what the Java 25 visitor already does inline.
Module test dependencies pulling in the Java parser as `testRuntimeOnly` referenced rewrite-java-21. Tests typically execute on a Java 25 JVM, so the parser ran on a newer javac than it was built against, exercising javac internals it doesn't fully match. Use rewrite-java-25 so each test suite exercises the parser intended for the runtime JVM.
…-25" This reverts commit fc93237.
Member
Author
|
We've since fixed the issue downstream by upgrading to |
greg-at-moderne
approved these changes
Apr 30, 2026
1 task
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
DCText/DCCommentgetBody()strips per-line leading whitespace that older versions preserved. When an older parser (e.g.rewrite-java-21) runs on a Java 25 JVM — asrewrite-static-analysisdoes in CI —visitTextfalls one character behind on every continuation line, dropping the*-margin trailing space and emitting a duplicated trailing char from the leftover-source branch invisitDocComment.\n, advance the cursor over any source whitespace that the body lacks at the corresponding position. Applied torewrite-java-{8,11,17,21}visitors; the Java 25 visitor already does this inline.JavadocTest(plain ASCII, non-ASCII, and HTML comment + plain text).Test plan
:rewrite-java-{17,21,25}:compatibilityTestgreen:rewrite-java-test:testgreenrewrite-static-analysistest suite green against local 8.82.0-SNAPSHOT (including the previously failingMavenJavadocNonAsciiRecipeTest)