Title: FormatterService.fixImports formats the whole file out of process · Issue #221 · openjavaformat/open-java-format · GitHub
Open Graph Title: FormatterService.fixImports formats the whole file out of process · Issue #221 · openjavaformat/open-java-format
X Title: FormatterService.fixImports formats the whole file out of process · Issue #221 · openjavaformat/open-java-format
Description: What happens FormatterService.fixImports formats the whole file when the formatter runs out of process. BootstrappingFormatterService.fixImports and NativeImageFormatterService.fixImports both call runFormatterCommand(input), which runs ...
Open Graph Description: What happens FormatterService.fixImports formats the whole file when the formatter runs out of process. BootstrappingFormatterService.fixImports and NativeImageFormatterService.fixImports both call...
X Description: What happens FormatterService.fixImports formats the whole file when the formatter runs out of process. BootstrappingFormatterService.fixImports and NativeImageFormatterService.fixImports both call...
Opengraph URL: https://github.com/openjavaformat/open-java-format/issues/221
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"FormatterService.fixImports formats the whole file out of process","articleBody":"### What happens\n\n`FormatterService.fixImports` formats the whole file when the formatter runs out of process. `BootstrappingFormatterService.fixImports` and `NativeImageFormatterService.fixImports` both call `runFormatterCommand(input)`, which runs `Main -` with no flags: the imports get fixed, and every line of the file is laid out again. `FormatterServiceImpl.fixImports`, in process, only fixes the imports.\n\nThe command line can do the right thing with `--fix-imports-only`; the services do not pass it. With the 21.0.2 native binary:\n\n```java\npackage p;\nimport java.util.Map;\nimport java.io.File;\nimport java.util.List;\nclass C { List\u003cString> l; Map\u003cString,String> m; }\n```\n\n`open-java-format --fix-imports-only -` gives\n\n```java\npackage p;\nimport java.util.List;\nimport java.util.Map;\n\nclass C { List\u003cString> l; Map\u003cString,String> m; }\n```\n\nand `open-java-format -`, which `fixImports` runs, gives the whole file formatted.\n\n### Why it matters\n\nNothing calls `fixImports` through these services today, so nobody sees it. It is what the IntelliJ plugin's import optimizer called while it existed: palantir/palantir-java-format#1078 added `PalantirJavaFormatImportOptimizer` on 2024-04-26, and palantir/palantir-java-format#1089 removed it on 2024-05-21 because \"optimizing imports via palantir-java-format is slow\". Every Optimize Imports started a JVM and reformatted the file. An import optimizer in the plugin needs this fixed first.\n\n### Proposal\n\n- Both services pass `--fix-imports-only` in `fixImports`.\n- `FormatterServicesTest` checks `fixImports` on the in-process, bootstrapping and native services: imports sorted and unused ones removed, the rest of the file as it was.\n","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-11-13T20:35:01Z","url":"https://github.com/openjavaformat/open-java-format/issues/221"}
| 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:93801d6e-9308-2c09-e012-69a3c5b3aaa4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A48:3451AC:96687:D0FF8:6AFBB793 |
| html-safe-nonce | 5fb3a0642514ddb513ac077d9eef3d22d7c0daa3976dca61869e7103a84c7ec5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTQ4OjM0NTFBQzo5NjY4NzpEMEZGODo2QUZCQjc5MyIsInZpc2l0b3JfaWQiOiIyMTQ5NjczMDM1MTQzODIxMjAzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 50780022a70b3c1cd36ab1442285d4f004d576adbda1bae1f625c9e20729dcca |
| hovercard-subject-tag | issue:6379493009 |
| 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/221/issue_layout |
| twitter:image | https://opengraph.githubassets.com/68da6148118ab71d611b962861a3856649221eaa6d14ad6a509fc60001ab1549/openjavaformat/open-java-format/issues/221 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/68da6148118ab71d611b962861a3856649221eaa6d14ad6a509fc60001ab1549/openjavaformat/open-java-format/issues/221 |
| og:image:alt | What happens FormatterService.fixImports formats the whole file when the formatter runs out of process. BootstrappingFormatterService.fixImports and NativeImageFormatterService.fixImports both call... |
| 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