Skip to content

Skip UseTextBlocks when literal value matches its source#1111

Merged
timtebeek merged 1 commit into
mainfrom
tim/fix-issue-1110
May 28, 2026
Merged

Skip UseTextBlocks when literal value matches its source#1111
timtebeek merged 1 commit into
mainfrom
tim/fix-issue-1110

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 28, 2026

Summary

  • UseTextBlocks was emitting broken text blocks for string literals containing supplementary characters encoded as surrogate pairs (e.g. "𝄠"), dropping the character and re-escaping content.

  • Root cause: the Java parser returns a corrupted J.Literal for these literals, where value equals valueSource (both stripped of the surrogate pair). The recipe then treated that quoted source form as content.

  • Fix: bail out of the conversion when value.equals(valueSource); that condition is impossible for a correctly decoded string literal, so it's a safe sentinel for parser corruption.

  • Fixes UseTextBlocks drops supplementary characters encoded as surrogate pairs and emits invalid output #1110

Test plan

  • Added regression test supplementaryCharacterAsSurrogatePair asserting the recipe leaves the original concatenation unchanged.
  • Full UseTextBlocksTest suite passes.

Defend against `J.Literal` values that come back identical to their
`valueSource` (observed for string literals containing supplementary
characters encoded as surrogate pairs). Skipping the conversion avoids
emitting a broken text block that drops or re-escapes content.

Fixes #1110
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 28, 2026
@timtebeek timtebeek merged commit 9cacf88 into main May 28, 2026
1 check passed
@timtebeek timtebeek deleted the tim/fix-issue-1110 branch May 28, 2026 08:38
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 28, 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.

UseTextBlocks drops supplementary characters encoded as surrogate pairs and emits invalid output

1 participant