Title: Bring over upstream PR #1731: keep a map factory's key and value on one line · Issue #31 · openjavaformat/open-java-format · GitHub
Open Graph Title: Bring over upstream PR #1731: keep a map factory's key and value on one line · Issue #31 · openjavaformat/open-java-format
X Title: Bring over upstream PR #1731: keep a map factory's key and value on one line · Issue #31 · openjavaformat/open-java-format
Description: A modern, lambda-friendly, 120 character Java formatter. - Bring over upstream PR #1731: keep a map factory's key and value on one line · Issue #31 · openjavaformat/open-java-format
Open Graph Description: A modern, lambda-friendly, 120 character Java formatter. - Bring over upstream PR #1731: keep a map factory's key and value on one line · Issue #31 · openjavaformat/open-java-format
X Description: A modern, lambda-friendly, 120 character Java formatter. - Bring over upstream PR #1731: keep a map factory's key and value on one line · Issue #31 · openjavaformat/open-java-format
Opengraph URL: https://github.com/openjavaformat/open-java-format
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bring over upstream PR #1731: keep a map factory's key and value on one line","articleBody":"### What\n\n[palantir/palantir-java-format#1731](https://github.com/palantir/palantir-java-format/pull/1731) by @ranpy13 keeps the key and the value of a `Map.of`-style call together when the call has to break. Today every argument goes on a line of its own. It closes upstream [#1602](https://github.com/palantir/palantir-java-format/issues/1602), is 3 files and +101 −5, and has been open since 2026-08-01 with no review and an unsigned CLA — where #1707 and #1786 were.\n\nMeasured here, with a jar built from the PR on top of 2.98.0.2:\n\n``` java\n// today\nstatic final Map\u003cString, String> plain = ImmutableMap.of(\n \"first key\",\n \"the first value\",\n \"second key\",\n \"the second value\");\n\n// with #1731\nstatic final Map\u003cString, String> plain = ImmutableMap.of(\n \"first key\", \"the first value\",\n \"second key\", \"the second value\");\n```\n\nIt applies to a call named `of` with an even number of arguments whose receiver's simple name is one of `Map`, `ImmutableMap`, `ImmutableSortedMap`, `ImmutableBiMap`, `SortedMap`, `NavigableMap`, `ConcurrentMap`. A call that fits on one line is unaffected, and so is one the existing tabular heuristic already lays out in pairs.\n\n### Why not in 2.x\n\nIt changes the output, which the 2.x line promises to keep identical to palantir-java-format 2.98.0. A file that is formatted today would fail a format check after the upgrade, which the PR says itself.\n\nHow much: of the 15,747 files of the JDK 21 sources, 54 contain such a call and **6 come out differently**. The formatter's error output over that corpus is unchanged.\n\n### To decide first\n\n- **Do we want this style at all?** One line per pair is easier to read in a long map, and it is what upstream #1602 asked for. Under the manifesto it is decided once for everyone: no option, no flag.\n- **Which release**, and what its number is — the same version-number question #22 raises for carried patches.\n- **Whether to wait for upstream.** If palantir merges it, take theirs at the next sync.\n\n### What the PR still needs\n\nFound while applying it here:\n\n- **Its test does not test it.** `MapOf.input` formatted with 2.98.0.2 already gives exactly `MapOf.output`, so the golden passes without the change. It needs a case that fails today, such as the long call above, whose arguments the tabular heuristic does not recognise.\n- **Only `of`, and only with a receiver.** `Map.ofEntries`, `ImmutableMap.builder()`, a statically imported `of(…)` and `Maps.immutableEntry` are untouched.\n- `SortedMap`, `NavigableMap` and `ConcurrentMap` have no static `of` in the JDK, so those three entries can only ever match a type of your own with that simple name. Matching a receiver by simple name is all a formatter that does not resolve types can do, but that deserves a comment.\n- **The patch is not formatted by this formatter:** `MAP_FACTORY_TYPES =ImmutableSet.of(`. `--dry-run --set-exit-if-changed` exits 1 on the file.\n\n### How\n\n- Cherry-pick with the original author, as in #22: this fork shares history with upstream, so rename detection maps `palantir-java-format/` to `open-java-format/` on its own. Tried here — the visitor hunks apply cleanly, and only the two new testdata files arrive as \"added in a renamed directory\".\n- The `palantir-8` golden here contains such a call; check whether its expected output moves.\n- The [Style page](https://openjavaformat.dev/style/) describes the output, so it changes with this.\n\n### Done when\n\n- a test fails without the change and passes with it;\n- a corpus run shows only map factory calls moving, and the release notes say so;\n- the Style page shows the new layout;\n- it ships in a release that is allowed to change the output.","author":{"url":"https://github.com/abashev","@type":"Person","name":"abashev"},"datePublished":"2026-09-22T17:09:43Z","url":"https://github.com/openjavaformat/open-java-format/issues/31"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:386a4b2d-e01a-25f6-a498-63278c14ee89 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B24:89D99:138B06:1B0B4B:6AFBBB5C |
| html-safe-nonce | a068ea5c7e1bbffd0e3a751739175ddc39dcb1787bc0417bab3e008b0da088ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjI0Ojg5RDk5OjEzOEIwNjoxQjBCNEI6NkFGQkJCNUMiLCJ2aXNpdG9yX2lkIjoiODk5MTM1NTI2NzE4Mzg5MDg0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 342ab64f227acc415eb2442ad98d22b604aadafafd68fff32c9a132e04527a47 |
| hovercard-subject-tag | repository:1288055459 |
| 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/openjavaformat/open-java-format/issues/31 |
| twitter:image | https://opengraph.githubassets.com/d68ef11eccab927066826db7c01d5e5330c9474f93b01c7830ce5a188e5db2ee/openjavaformat/open-java-format |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d68ef11eccab927066826db7c01d5e5330c9474f93b01c7830ce5a188e5db2ee/openjavaformat/open-java-format |
| og:image:alt | A modern, lambda-friendly, 120 character Java formatter. - Bring over upstream PR #1731: keep a map factory's key and value on one line · Issue #31 · openjavaformat/open-java-format |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2b2ef9c1578c18d8ed27027940544c958743213cf4461659f14d3ccdf51e162c |
| turbo-cache-control | no-cache |
| 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