Skip to content

Java: realign Javadoc cursor when javac strips continuation whitespace#7531

Merged
timtebeek merged 3 commits intomainfrom
tim/javadoc-cursor-fix
Apr 30, 2026
Merged

Java: realign Javadoc cursor when javac strips continuation whitespace#7531
timtebeek merged 3 commits intomainfrom
tim/javadoc-cursor-fix

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • Java 23+ javac's DCText/DCComment getBody() strips per-line leading whitespace that older versions preserved. When an older parser (e.g. rewrite-java-21) runs on a Java 25 JVM — as rewrite-static-analysis does in CI — 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. Applied to rewrite-java-{8,11,17,21} visitors; the Java 25 visitor already does this inline.
  • Adds three round-trip regression tests in JavadocTest (plain ASCII, non-ASCII, and HTML comment + plain text).

Test plan

  • :rewrite-java-{17,21,25}:compatibilityTest green
  • :rewrite-java-test:test green
  • Full rewrite-static-analysis test suite green against local 8.82.0-SNAPSHOT (including the previously failing MavenJavadocNonAsciiRecipeTest)

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.
@timtebeek
Copy link
Copy Markdown
Member Author

We've since fixed the issue downstream by upgrading to rewrite-java-25 there when running our tests on Java 25:

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Apr 30, 2026
@timtebeek timtebeek merged commit 23c19e9 into main Apr 30, 2026
1 check passed
@timtebeek timtebeek deleted the tim/javadoc-cursor-fix branch April 30, 2026 14:36
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants