Skip to content

Keep \t and \f escapes in UseTextBlocks to avoid incidental whitespace stripping#1160

Merged
timtebeek merged 1 commit into
mainfrom
tim/1158-usetextblocks-tab-escape
Jul 1, 2026
Merged

Keep \t and \f escapes in UseTextBlocks to avoid incidental whitespace stripping#1160
timtebeek merged 1 commit into
mainfrom
tim/1158-usetextblocks-tab-escape

Conversation

@timtebeek

@timtebeek timtebeek commented Jul 1, 2026

Copy link
Copy Markdown
Member

What's changed

UseTextBlocks decodes each concatenated string literal to its value before emitting text-block content, which turns escape sequences like \t and \f into literal tab/form-feed characters. When such a literal ends up on a content line's leading edge, javac cannot distinguish it from incidental leading whitespace and strips it during text-block whitespace processing (JLS 3.10.6) — silently changing the string's value (e.g. "\tb" compiles to "b").

This re-escapes tab and form-feed characters back to \t / \f escape sequences when generating text-block content, right after backslash escaping so the introduced backslashes aren't doubled. Indentation added later is unaffected.

Testing

Added keepTabEscapeToAvoidIncidentalWhitespaceStripping and keepFormFeedEscapeToAvoidIncidentalWhitespaceStripping, matching the reproduction in the issue. Full UseTextBlocksTest suite passes.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jul 1, 2026
@timtebeek timtebeek merged commit 4cd2123 into main Jul 1, 2026
1 check passed
@timtebeek timtebeek deleted the tim/1158-usetextblocks-tab-escape branch July 1, 2026 12:56
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jul 1, 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 unescapes \t into a literal tab, which incidental-whitespace stripping can silently corrupt at compile time

1 participant