Preserve escaped backslash-newline text in UsePortableNewlines - #1006
Draft
martinfrancois wants to merge 3 commits into
Draft
Preserve escaped backslash-newline text in UsePortableNewlines#1006martinfrancois wants to merge 3 commits into
UsePortableNewlines#1006martinfrancois wants to merge 3 commits into
Conversation
4 tasks
martinfrancois
force-pushed
the
agent/repro-use-portable-newlines-escaped-backslash
branch
from
August 15, 2026 21:13
94e423b to
22f04ed
Compare
martinfrancois
force-pushed
the
agent/repro-use-portable-newlines-escaped-backslash
branch
from
August 16, 2026 02:53
22f04ed to
7279347
Compare
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.
Suggested review order: 9 of 52 (Score: 8)
Review first: #988
What's changed?
Updates
UsePortableNewlinesto distinguish a Java newline escape from an escaped backslash followed byn. The recipe keepsJ.Literal.valueandJ.Literal.valueSourcealigned for ordinary strings and text blocks, including Unicode escapes, octal line feeds, CRLF input, and text-block continuations.What's your motivation?
Recipe:
org.openrewrite.staticanalysis.UsePortableNewlines.I found this by running
org.openrewrite.staticanalysis.UsePortableNewlinesfromorg.openrewrite.recipe:rewrite-static-analysis:2.39.0onCodexModelDefaultsResolverTest.javain Symphony-Trello ata8013f27. I reproduced the same result with the latest released recipe artifact,org.openrewrite.recipe:rewrite-static-analysis:2.41.0../mvnw -DskipTests test-compilethen fails withillegal escape characterin this file and three other affected test files.Before
Actual after the recipe
Expected after the recipe
(unchanged)The source contains data for a generated shell script: two Java backslashes encode one runtime backslash. Replacing the
ncreates the invalid Java escape\%, so the transformed checkout no longer compiles.Confirmed real-world execution
CodexModelDefaultsResolverTest.javaata8013f27.martinfrancois/symphony-trello@a8013f27.Anything in particular you'd like reviewers to focus on?
Please review the source-to-runtime newline mapping. A formatter newline such as
"line=%s\\n"remains eligible, while escaped backslash-newline data remains unchanged.Have you considered any alternatives or workarounds?
Counting only consecutive raw backslashes does not account for Unicode escapes or text-block continuations and leaves the literal's semantic value inconsistent with its printed source in those cases.
Any additional context
Pre-existing tests changed: None.
martinfrancois/symphony-trello@a8013f27org.openrewrite.recipe:rewrite-static-analysis:2.39.0org.openrewrite.recipe:rewrite-static-analysis:2.41.0UsePortableNewlinesTest.doesNotCorruptEscapedBackslashNewlineInFormattedTextBlockopenrewrite/rewrite-static-analysis@43b51de2This change was prepared with AI assistance. I reviewed the target execution evidence, implementation, tests, and contribution text.
Checklist
./gradlew buildlocally, and committed any resulting changes torecipes.csv