Preserve Unicode escapes in Javadoc HTML element and attribute names#7394
Merged
Preserve Unicode escapes in Javadoc HTML element and attribute names#7394
Conversation
When the Java compiler expands Unicode escapes (e.g. `\u00ef`) before the `com.sun.source.doctree` parser runs, the parser returns the decoded character but the source still contains the 6-character escape. The existing `cursor += name.length()` in `visitStartElement`, `visitEndElement`, and `visitAttribute` assumed one source char per name char, drifting the cursor and breaking print idempotency. Consume names using the same escape-aware logic already present in `visitText`.
sambsnyd
approved these changes
Apr 16, 2026
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
Fixes an
IllegalStateException: ... is not print idempotentwhen parsing Javadoc containing Unicode-escaped characters (e.g.<\u00ef>) as HTML element/attribute names. The Java compiler decodes\u00efintoïbefore thecom.sun.source.doctreeparser runs, but the raw source still contains the 6-char escape — socursor += name.length()invisitStartElement,visitEndElement, andvisitAttributedrifted by 5 chars and mangled subsequent tag parsing. Fixed by consuming names with the same escape-aware logic already used invisitText, applied across all fiveReloadableJavaNJavadocVisitorimplementations (Java 8/11/17/21/25), with a shared reproducer added torewrite-java-tck'sJavadocTest.Test plan
./gradlew :rewrite-java-8:compatibilityTest :rewrite-java-11:compatibilityTest :rewrite-java-17:compatibilityTest :rewrite-java-21:compatibilityTest :rewrite-java-25:compatibilityTest --tests "org.openrewrite.java.tree.JavadocTest"