Title: Keep //$NON-NLS-n$ markers valid: no inserted space, each marker on the line of its string · Issue #23 · openjavaformat/open-java-format · GitHub
Open Graph Title: Keep //$NON-NLS-n$ markers valid: no inserted space, each marker on the line of its string · Issue #23 · openjavaformat/open-java-format
X Title: Keep //$NON-NLS-n$ markers valid: no inserted space, each marker on the line of its string · Issue #23 · openjavaformat/open-java-format
Description: Background Eclipse marks a string literal that is deliberately not externalised with a trailing //$NON-NLS-n$ comment, where n is the position of the literal on that line. The marker has to keep its exact spelling and has to stay on the ...
Open Graph Description: Background Eclipse marks a string literal that is deliberately not externalised with a trailing //$NON-NLS-n$ comment, where n is the position of the literal on that line. The marker has to keep it...
X Description: Background Eclipse marks a string literal that is deliberately not externalised with a trailing //$NON-NLS-n$ comment, where n is the position of the literal on that line. The marker has to keep it...
Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/23
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Keep //$NON-NLS-n$ markers valid: no inserted space, each marker on the line of its string","articleBody":"### Background\n\nEclipse marks a string literal that is deliberately not externalised with a trailing `//$NON-NLS-n$` comment, where `n` is the position of the literal **on that line**. The marker has to keep its exact spelling and has to stay on the line of its string. [This answer](https://stackoverflow.com/a/40266605) explains the convention. The item comes from the \"Future work\" list of the old README.\n\nChains of string concatenation already work: `OpsBuilder` keeps each marker with its string, and `NON-NLS.input` / `NON-NLS.output` cover that. Three other cases break. All of them reproduce with 2.98.0.1, with the jar and the native binary alike, in every style.\n\n### 1. A space is inserted into the marker\n\n```java\nString a = \"x\"; //$NON-NLS-1$\n```\n\nbecomes\n\n```java\nString a = \"x\"; // $NON-NLS-1$\n```\n\nand Eclipse no longer recognises it. This is the most common case, because it hits every statement that fits on one line.\n\nCause: `doc/Comment.computeFlat()` prefixes `// ` to any line comment that does not start with it. For a statement that fits on one line `commentsHelper.rewrite` is never called, so the exemption that `JavaCommentsHelper.LINE_COMMENT_MISSING_SPACE_PREFIX` already has for `//noinspection` and `//$NON-NLS-n$` is bypassed. `computeWidth()` carries the matching `+ 1`. A trailing `//noinspection` gets the same space; on a line of its own it is left alone.\n\n### 2. Wrapped arguments leave their markers behind\n\n```java\nString message = Messages.format(\"first argument that is long enough to matter\", \"second argument that is also rather long\", \"third one\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n```\n\nbecomes\n\n```java\nString message = Messages.format(\n \"first argument that is long enough to matter\",\n \"second argument that is also rather long\",\n \"third one\"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$\n```\n\nThe first two literals are now on lines without a marker, and the last line has one literal and three markers.\n\n### 3. A reflowed literal ends up partly unmarked\n\n```java\nString reflowed = \"a single string literal that is far too long to fit into one hundred and twenty columns, so the formatter reflows it\"; //$NON-NLS-1$\n```\n\nbecomes\n\n```java\nString reflowed =\n \"a single string literal that is far too long to fit into one hundred and twenty columns, so the\"\n + \" formatter reflows it\"; //$NON-NLS-1$\n```\n\nThe first piece has no marker. `--skip-reflowing-long-strings` avoids this case only.\n\n### Proposal\n\n- **Case 1** is small: apply the existing exemption in `Comment.computeFlat()` and `Comment.computeWidth()`, sharing the pattern with `JavaCommentsHelper` instead of repeating it.\n- **Cases 2 and 3** need a design. When a statement with markers is wrapped, each marker has to move to the line of its literal and be renumbered for that line. When a literal is split, every piece needs a marker of its own.\n\n### Compatibility\n\nAll three fixes change the output of files that format today, so they differ from palantir-java-format 2.98.0. The promise for 2.x says output changes wait for 3.0. Case 1 is a bug that makes the formatter corrupt a marker another tool depends on, so it is worth deciding whether it counts as a fix or as a style change.\n\n### Prior reports\n\ngoogle-java-format shares this code path and has had it reported: google/google-java-format#221 (closed, 2017) and google/google-java-format#361 (open since 2019). No report was found in palantir-java-format.\n\n","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-09-21T13:39:20Z","url":"https://github.com/openjavaformat/open-java-format/issues/23"}
| 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:eae72e17-70a2-ae1c-3e52-b06b20d36054 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D884:2F1A1A:5A1C28:778D86:6AFBC716 |
| html-safe-nonce | 5f5a1453a9a814ec063b34c1ee8ea6f0b2ac03fd1cc0d2800157b5e5958a0b5c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODg0OjJGMUExQTo1QTFDMjg6Nzc4RDg2OjZBRkJDNzE2IiwidmlzaXRvcl9pZCI6IjE3NTc3OTU4NDI0ODUxMTA1NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2805f99935633c089fc955c201a37cd7551b10e121fd91880b86ad954c4680e3 |
| hovercard-subject-tag | issue:5527762633 |
| 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/23/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1ee3a5609e0650eb61f49641e9431741edc26699add0eaa13d3e19ebb3d92d85/openjavaformat/open-java-format/issues/23 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1ee3a5609e0650eb61f49641e9431741edc26699add0eaa13d3e19ebb3d92d85/openjavaformat/open-java-format/issues/23 |
| og:image:alt | Background Eclipse marks a string literal that is deliberately not externalised with a trailing //$NON-NLS-n$ comment, where n is the position of the literal on that line. The marker has to keep it... |
| 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 | d440bda0d812801778b27bfe9f7c1ce9ff22420c73f6f95150c4fcbca311c50b |
| 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 | 2c43021aed8695990c86c0eaaedc600bfeffec36 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width