Title: A long string containing \\t fails to format: spurious "unclosed string literal" · Issue #32 · openjavaformat/open-java-format · GitHub
Open Graph Title: A long string containing \\t fails to format: spurious "unclosed string literal" · Issue #32 · openjavaformat/open-java-format
X Title: A long string containing \\t fails to format: spurious "unclosed string literal" · Issue #32 · openjavaformat/open-java-format
Description: What Reported upstream as palantir/palantir-java-format#1680 (open since 2026-05-29, no comments). It reproduces here on 2.98.0.2. Minimal case: class C { void m(java.sql.Connection con) throws Exception { con.createStatement() .execute(...
Open Graph Description: What Reported upstream as palantir/palantir-java-format#1680 (open since 2026-05-29, no comments). It reproduces here on 2.98.0.2. Minimal case: class C { void m(java.sql.Connection con) throws Exc...
X Description: What Reported upstream as palantir/palantir-java-format#1680 (open since 2026-05-29, no comments). It reproduces here on 2.98.0.2. Minimal case: class C { void m(java.sql.Connection con) throws Exc...
Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/32
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"A long string containing \\\\t fails to format: spurious \"unclosed string literal\"","articleBody":"### What\n\nReported upstream as [palantir/palantir-java-format#1680](https://github.com/palantir/palantir-java-format/issues/1680) (open since 2026-05-29, no comments). It reproduces here on 2.98.0.2. Minimal case:\n\n``` java\nclass C {\n void m(java.sql.Connection con) throws Exception {\n con.createStatement()\n .execute(\"ALTER DATABASE tempdb MODIFY FILE (NAME = 'tempdev', FILENAME = 'D:\\\\tempDb\\\\DATA\\\\tempdb.mdf')\");\n }\n}\n```\n\n`open-java-format C.java` exits 2 with `C.java:5:26: error: unclosed string literal`, while `javac` compiles the same file. Replace the escaped backslashes with forward slashes and the file formats.\n\nIn the upstream report the errors point at methods further down the file, which makes the cause hard to see: the line and column come from the rewritten source the formatter parses to check itself, not from the file on disk.\n\n### Why it happens\n\n`StringWrapper.stringComponents` splits the literal's source text at whitespace and at escaped whitespace, and `hasEscapedWhitespaceAt`/`hasEscapedNewlineAt` look for `\\t`, `\\n` and `\\r` without asking whether that backslash is itself escaped. In `DATA\\\\tempDb` the second backslash and the `t` look like an escaped tab, so the split lands inside the escaped backslash. `StringWrapper.getReflowReplacements` on the file above returns:\n\n``` java\n\"ALTER DATABASE tempdb MODIFY FILE (NAME = 'tempdev', FILENAME = 'D:\\\\tempDb\\\\DATA\\\"\n + \"\\tempdb.mdf')\"\n```\n\nThe first piece ends in a lone backslash, which escapes the closing quote — that is the error. The second piece starts with `\\t`, a tab, so even if it parsed the string would no longer be the one the author wrote.\n\n`\\n` and `\\r` are mis-read the same way, but that branch advances past the escape, so the split is merely in an odd place and the result still parses and still means the same: the same file with `D:\\\\nempDb` formats fine. Only `\\\\t` produces code that does not parse.\n\n### Fix\n\nWalk the literal left to right consuming escape sequences, so that `\\\\` takes two characters and the `t` after it is an ordinary letter.\n\nMind the output promise: files whose long strings contain `\\\\n` or `\\\\r` format today, and the fix moves where they are split, so their output changes. Measure that over a corpus and decide which release it belongs to, as in #22 and #31.\n\n### Done when\n\n- the file above formats, and formatting it twice is a no-op;\n- a golden covers a wrapped literal with `\\\\t`, `\\\\n`, `\\\\r`, `\\\\\\\\` and `\\u` escapes, and fails without the fix;\n- a test asserts the string's value is unchanged by wrapping, not only that the result parses;\n- a corpus run says how many files the `\\\\n`/`\\\\r` split moves.","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-09-22T17:17:54Z","url":"https://github.com/openjavaformat/open-java-format/issues/32"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9aca30bb-1cbf-750a-9526-d78f9cada3b8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B44E:32BC13:133C40:1A7E9F:6AFBBB59 |
| html-safe-nonce | e03f05dd73b7ab87aa6e85b4f95a1d8bfd896e265920b7c8b7554f38cd0e166d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDRFOjMyQkMxMzoxMzNDNDA6MUE3RTlGOjZBRkJCQjU5IiwidmlzaXRvcl9pZCI6IjU2MTU1MTU2MjUwMDM0MDAwMjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e281cdd64eb8ac1f2d9989a3490b8a9033ca092858ddac1b3c07a20c8eb2bcd4 |
| hovercard-subject-tag | issue:5542847953 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openjavaformat/open-java-format/32/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ae32e36e30ff16b4c1e7036140a076ae964107afe569716129a0b5f92573b0d/openjavaformat/open-java-format/issues/32 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ae32e36e30ff16b4c1e7036140a076ae964107afe569716129a0b5f92573b0d/openjavaformat/open-java-format/issues/32 |
| og:image:alt | What Reported upstream as palantir/palantir-java-format#1680 (open since 2026-05-29, no comments). It reproduces here on 2.98.0.2. Minimal case: class C { void m(java.sql.Connection con) throws Exc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | abashev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| turbo-cache-control | no-preview |
| go-import | github.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git |
| octolytics-dimension-user_id | 325177626 |
| octolytics-dimension-user_login | openjavaformat |
| octolytics-dimension-repository_id | 1288055459 |
| octolytics-dimension-repository_nwo | openjavaformat/open-java-format |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 214273098 |
| octolytics-dimension-repository_parent_nwo | palantir/palantir-java-format |
| octolytics-dimension-repository_network_root_id | 214273098 |
| octolytics-dimension-repository_network_root_nwo | palantir/palantir-java-format |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e4cce0e99cf61481a318ff12c2e8580153a6c7c6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width