René's URL Explorer Experiment


Title: The routes format the same file differently: formatDiff on the JVM, ranges, and the order of fixing imports · Issue #219 · openjavaformat/open-java-format · GitHub

Open Graph Title: The routes format the same file differently: formatDiff on the JVM, ranges, and the order of fixing imports · Issue #219 · openjavaformat/open-java-format

X Title: The routes format the same file differently: formatDiff on the JVM, ranges, and the order of fixing imports · Issue #219 · openjavaformat/open-java-format

Description: What happens The same file comes out differently depending on the route that formats it. Found by running every route on the same input with 21.0.2 on JDK 21, the native binary for macOS aarch64 included, over 3,865 real files: 3,000 fro...

Open Graph Description: What happens The same file comes out differently depending on the route that formats it. Found by running every route on the same input with 21.0.2 on JDK 21, the native binary for macOS aarch64 in...

X Description: What happens The same file comes out differently depending on the route that formats it. Found by running every route on the same input with 21.0.2 on JDK 21, the native binary for macOS aarch64 in...

Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/219

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"The routes format the same file differently: formatDiff on the JVM, ranges, and the order of fixing imports","articleBody":"### What happens\n\nThe same file comes out differently depending on the route that formats it. Found by running every route on the same input with 21.0.2 on JDK 21, the native binary for macOS aarch64 included, over 3,865 real files: 3,000 from a set of local repositories and 865 from `java.base` of JDK 21.\n\n**1. `formatDiff` on the JVM does not reflow long strings; with the native binary it does.** A changed line\n\n```java\n    String s = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n```\n\nbecomes, without `openjavaformat.native.formatter`,\n\n```java\n    String s =\n            \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\";\n```\n\nand with it\n\n```java\n    String s = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et\"\n            + \" dolore magna aliqua.\";\n```\n\nThe first fails the check of the GitHub Action and the pre-commit hook (`--dry-run --set-exit-if-changed` with the native binary); the second passes.\n\n**2. Formatting a range reflows long strings outside it.** IntelliJ IDEA, with the Java-based formatter and the native one alike, and `formatDiff` with the native binary: once a line in the ranges needs wrapping, every long string in the file is reflowed, on lines nobody touched. Only `changed` is on a changed line here:\n\n```diff\n class S {\n-    String outside = \"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat sed.\";\n+    String outside = \"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\"\n+            + \" consequat sed.\";\n\n-    String changed = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna.\";\n+    String changed =\n+            \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et\"\n+                    + \" dolore magna.\";\n }\n```\n\nOver every line with a string literal and more than 90 characters in 600 of the files, formatted one line at a time, the reflow changed 11 results, and in 2 of them it changed strings outside the code that formatting the line rewrote.\n\n**3. The Maven plugin and the Spotless step fix the imports before formatting; the command line, the native binary, the GitHub Action, the pre-commit hook and the playground fix them after it.** The result differs when an import that is removed has a comment. From `java/nio/charset/CharsetEncoder.java` in JDK 21, where `import java.nio.charset.CoderMalfunctionError;                  // javadoc` is removed:\n\n```\nbefore (Maven plugin, Spotless step)   after (command line, native binary)\nimport java.lang.ref.WeakReference;    import java.lang.ref.WeakReference;\nimport java.nio.Buffer;                // javadoc\nimport java.nio.ByteBuffer;            import java.nio.Buffer;\nimport java.nio.CharBuffer;            import java.nio.ByteBuffer;\n// javadoc                             import java.nio.CharBuffer;\n```\n\nA comment right under a removed import gets a blank line between it and the class before, and stays on the class after. And `import java.util.List;;` followed by another import, which javac 21 rejects with `--release 21` and accepts with a warning below it: the Maven plugin and the Spotless step drop the semicolon and format the file, the command line fails with `extraneous semicolon`.\n\nThis is rare: 1 of the 3,865 files, as they are and with an unused import added to each. Each order passes its check on what the other wrote, so no build fails on it; it decides what a file looks like after it is first formatted.\n\n### Why\n\n- **1.** The Gradle plugin loads `FormatterServiceImpl` into its own JVM, and its `getFormatReplacements` calls `Formatter.getFormatReplacements`, which never reflows strings. The bootstrapping and native services run `Main --output-replacements`, where `FormatFileCallable` reflows them after the replacements.\n- **2.** That reflow gets the whole file, and its result goes back as one replacement of the whole file. The ranges only decide whether to reflow at all, through `StringWrapper.linesNeedWrapping`, which compares the ranges of the input with the lines of the formatted text.\n- **3.** `Formatter.formatSourceAndFixImports`, behind `FormatterService.formatSourceReflowStringsAndFixImports`, runs `ImportOrderer`, `RemoveUnusedImports`, `formatSource`, `StringWrapper`; `FormatFileCallable.formatFile` runs `formatSource`, `RemoveUnusedImports`, `ImportOrderer`, `StringWrapper`. `ImportOrderer` moves a comment along with its import, and `RemoveUnusedImports` leaves the comment of an import it removes behind, so the order decides where that comment ends up. The command line has to format first: the ranges of `--lines` and `--offset` are offsets into the input.\n\nNo test runs the in-process service against the others: `FormatterServicesTest` and `FormatDiffTest` cover the bootstrapping and native services only.\n\n### Proposal\n\n- One method formats the ranges and reflows the strings, for `--output-replacements` and for `FormatterServiceImpl.getFormatReplacements`.\n- With ranges, `StringWrapper` reflows only the literals in the code that formatting the ranges rewrites, moving the ranges along with each of its passes. Without ranges it stays as it is, so whole-file formatting does not change.\n- `formatSourceAndFixImports` fixes the imports after formatting, as the command line does.\n- Tests hold the in-process service to what the command line prints, and `FormatterServicesTest` and `FormatDiffTest` run the in-process formatter too.\n\n### Not here\n\n- Spotless' own `palantirJavaFormat()` step runs the formatter through Spotless' code, which never reflows strings. That is Spotless' to change; the docs say so.\n- The Eclipse plugin formats with `Formatter.getFormatReplacements` and does not reflow strings either.\n- `open-java-format --lines` without `--output-replacements` still reflows the whole file.\n","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-11-12T20:47:13Z","url":"https://github.com/openjavaformat/open-java-format/issues/219"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6d5846fa-d87c-c3f9-ded5-fb53dd3637df
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9FB8:6188:38B56C:4B234C:6AFBBB5C
html-safe-noncec675c2626b81e09c8f280b0ba4ad8a54e1299b4ea1804f71e305c9267848f5b2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkI4OjYxODg6MzhCNTZDOjRCMjM0Qzo2QUZCQkI1QyIsInZpc2l0b3JfaWQiOiI0ODg0NzA2MzAyMjcxMTQyNzQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac90574cb02af0be1da1a4ebe9f126d85e6d134e2075565857f69aa4d3191e69e9
hovercard-subject-tagissue:6358710408
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openjavaformat/open-java-format/219/issue_layout
twitter:imagehttps://opengraph.githubassets.com/472c528f34980bb701f668d202e694a8d8a6ca40cdc3c68dee2c94c7c95a85b7/openjavaformat/open-java-format/issues/219
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/472c528f34980bb701f668d202e694a8d8a6ca40cdc3c68dee2c94c7c95a85b7/openjavaformat/open-java-format/issues/219
og:image:altWhat happens The same file comes out differently depending on the route that formats it. Found by running every route on the same input with 21.0.2 on JDK 21, the native binary for macOS aarch64 in...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameabashev
hostnamegithub.com
expected-hostnamegithub.com
None2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c
turbo-cache-controlno-preview
go-importgithub.com/openjavaformat/open-java-format git https://github.com/openjavaformat/open-java-format.git
octolytics-dimension-user_id325177626
octolytics-dimension-user_loginopenjavaformat
octolytics-dimension-repository_id1288055459
octolytics-dimension-repository_nwoopenjavaformat/open-java-format
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forktrue
octolytics-dimension-repository_parent_id214273098
octolytics-dimension-repository_parent_nwopalantir/palantir-java-format
octolytics-dimension-repository_network_root_id214273098
octolytics-dimension-repository_network_root_nwopalantir/palantir-java-format
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee4cce0e99cf61481a318ff12c2e8580153a6c7c6
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/openjavaformat/open-java-format/issues/219#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenjavaformat%2Fopen-java-format%2Fissues%2F219
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fopenjavaformat%2Fopen-java-format%2Fissues%2F219
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=openjavaformat%2Fopen-java-format
Reloadhttps://github.com/openjavaformat/open-java-format/issues/219
Reloadhttps://github.com/openjavaformat/open-java-format/issues/219
Reloadhttps://github.com/openjavaformat/open-java-format/issues/219
openjavaformathttps://github.com/openjavaformat
open-java-formathttps://github.com/openjavaformat/open-java-format
Codehttps://github.com/openjavaformat/open-java-format
Issues30 (30)https://github.com/openjavaformat/open-java-format/issues
Pull requests5 (5)https://github.com/openjavaformat/open-java-format/pulls
Discussionshttps://github.com/openjavaformat/open-java-format/discussions
Actionshttps://github.com/openjavaformat/open-java-format/actions
Security and qualityhttps://github.com/openjavaformat/open-java-format/security
Insightshttps://github.com/openjavaformat/open-java-format/pulse
https://github.com/openjavaformat/open-java-format
New issuehttps://github.com/login?return_to=https://github.com/openjavaformat/open-java-format/issues/219
New issuehttps://github.com/login?return_to=https://github.com/openjavaformat/open-java-format/issues/219
#220https://github.com/openjavaformat/open-java-format/pull/220
The routes format the same file differently: formatDiff on the JVM, ranges, and the order of fixing importshttps://github.com/openjavaformat/open-java-format/issues/219#top
#220https://github.com/openjavaformat/open-java-format/pull/220
bugSomething isn't workinghttps://github.com/openjavaformat/open-java-format/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/abashev
abashevhttps://github.com/abashev
on Nov 12, 2026https://github.com/openjavaformat/open-java-format/issues/219#issue-6358710408
abashevhttps://github.com/abashev
bugSomething isn't workinghttps://github.com/openjavaformat/open-java-format/issues?q=state%3Aopen%20label%3A%22bug%22
on Nov 12, 2026https://github.com/openjavaformat/open-java-format/issues/219#event-35960198186
abashevhttps://github.com/abashev
on Nov 12, 2026https://github.com/openjavaformat/open-java-format/issues/219#event-35963843554
Expect what the command line prints for a comment in a module namehttps://github.com/openjavaformat/open-java-format/commit/b06ccee5a4656924b6298f06a2f64e283c8661a6
b06cceehttps://github.com/openjavaformat/open-java-format/commit/b06ccee5a4656924b6298f06a2f64e283c8661a6
Return what --output-replacements prints from the in-process servicehttps://github.com/openjavaformat/open-java-format/commit/7f2123193885357f5c49447fb5edaaaae01dc19b
7f21231https://github.com/openjavaformat/open-java-format/commit/7f2123193885357f5c49447fb5edaaaae01dc19b
Reflow only the strings in the code that formatting the ranges rewriteshttps://github.com/openjavaformat/open-java-format/commit/f9dbb65d01e8bbc7cb96e7b218116dbec3de7011
f9dbb65https://github.com/openjavaformat/open-java-format/commit/f9dbb65d01e8bbc7cb96e7b218116dbec3de7011
Reflow long strings in the Eclipse plugin's ranges, as on the command…https://github.com/openjavaformat/open-java-format/commit/c36e9b1e83aad595c17a5a0ef7871b240a7b4ee7
c36e9b1https://github.com/openjavaformat/open-java-format/commit/c36e9b1e83aad595c17a5a0ef7871b240a7b4ee7
Return what --output-replacements prints from the in-process servicehttps://github.com/openjavaformat/open-java-format/commit/740704f53a4118cf2f43c0beece9f17c33bc736f
740704fhttps://github.com/openjavaformat/open-java-format/commit/740704f53a4118cf2f43c0beece9f17c33bc736f
Reflow only the strings in the code that formatting the ranges rewriteshttps://github.com/openjavaformat/open-java-format/commit/95b054042e4ea440c562fb05a2584a675c387b89
95b0540https://github.com/openjavaformat/open-java-format/commit/95b054042e4ea440c562fb05a2584a675c387b89
Reflow long strings in the Eclipse plugin's ranges, as on the command…https://github.com/openjavaformat/open-java-format/commit/5894a4fee35f285cf3f1ab90f21cc71138aeff43
5894a4fhttps://github.com/openjavaformat/open-java-format/commit/5894a4fee35f285cf3f1ab90f21cc71138aeff43
abashevhttps://github.com/abashev
completedhttps://github.com/openjavaformat/open-java-format/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#220https://github.com/openjavaformat/open-java-format/pull/220
on Nov 16, 2026https://github.com/openjavaformat/open-java-format/issues/219#event-36321987682
abashevhttps://github.com/abashev
on Nov 16, 2026https://github.com/openjavaformat/open-java-format/issues/219#event-36322889874
Return what --output-replacements prints from the in-process servicehttps://github.com/openjavaformat/open-java-format/commit/bac4aa5084e3d7a27b7f14611be614c316e9a263
bac4aa5https://github.com/openjavaformat/open-java-format/commit/bac4aa5084e3d7a27b7f14611be614c316e9a263
Reflow only the strings in the code that formatting the ranges rewriteshttps://github.com/openjavaformat/open-java-format/commit/a740c203e9871f7f4c8b31535ef51c77d240a340
a740c20https://github.com/openjavaformat/open-java-format/commit/a740c203e9871f7f4c8b31535ef51c77d240a340
Reflow long strings in the Eclipse plugin's ranges, as on the command…https://github.com/openjavaformat/open-java-format/commit/86741cf6fb7652b29e456bca10a00ca8e63f6854
86741cfhttps://github.com/openjavaformat/open-java-format/commit/86741cf6fb7652b29e456bca10a00ca8e63f6854
Sign up for freehttps://github.com/signup?return_to=https://github.com/openjavaformat/open-java-format/issues/219
Sign in to commenthttps://github.com/login?return_to=https://github.com/openjavaformat/open-java-format/issues/219
bugSomething isn't workinghttps://github.com/openjavaformat/open-java-format/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.