Repository: palantir/palantir-java-format
Pull request #1240: Native image IncludeAllLocales
Author: login: crogoz
Labels: name: autorelease
name: merge when ready
Created: 2025-03-18T12:46:10Z | Merged: 2025-03-19T11:35:15Z

## Before this PR
<!-- What's wrong with the current state of the world and why change it now? -->

## After this PR
Fixes: https://github.com/palantir/palantir-java-format/issues/1238

<!-- User-facing outcomes this PR delivers go below -->
==COMMIT_MSG==
Native image IncludeAllLocales and updates reachability-metadata's resources glob to include all entries under `com/sun/tools/javac/resources/**`
==COMMIT_MSG==

## Possible downsides?
<!-- Please describe any way users could be negatively affected by this PR. -->




Diff:
diff --git a/changelog/@unreleased/pr-1240.v2.yml b/changelog/@unreleased/pr-1240.v2.yml
new file mode 100644
index 000000000..ea33554fc
--- /dev/null
+++ b/changelog/@unreleased/pr-1240.v2.yml
@@ -0,0 +1,6 @@
+type: fix
+fix:
+  description: Native image IncludeAllLocales and updates reachability-metadata's
+    resources glob to include all entries under `com/sun/tools/javac/resources/**`
+  links:
+  - https://github.com/palantir/palantir-java-format/pull/1240
diff --git a/palantir-java-format-jdk-bootstrap/src/test/java/com/palantir/javaformat/bootstrap/FormatterServicesTest.java b/palantir-java-format-jdk-bootstrap/src/test/java/com/palantir/javaformat/bootstrap/FormatterServicesTest.java
index bb34a69fb..ab1a9ea93 100644
--- a/palantir-java-format-jdk-bootstrap/src/test/java/com/palantir/javaformat/bootstrap/FormatterServicesTest.java
+++ b/palantir-java-format-jdk-bootstrap/src/test/java/com/palantir/javaformat/bootstrap/FormatterServicesTest.java
@@ -78,6 +78,23 @@ void can_format_large_input_file(FormatterService formatterService) throws Forma
         });
     }
 
+    @ParameterizedTest
+    @MethodSource("getFormatters")
+    void no_replacements_for_invalid_input(FormatterService formatterService) throws FormatterException {
+        String input =
+                """
+            class Foo {
+
+            /* hello*/
+            public void main(     String    aaaa ) {
+                System.out.println("aaaaa"}; }
+            }
+        """;
+
+        assertThat(formatterService.getFormatReplacements(input, List.of(Range.open(0, input.length()))))
+                .isEmpty();
+    }
+
     private static Stream<FormatterService> getFormatters() {
         return Stream.of(
                 new BootstrappingFormatterService(
diff --git a/palantir-java-format-native/build.gradle b/palantir-java-format-native/build.gradle
index 1408b747e..76f0a2f03 100644
--- a/palantir-java-format-native/build.gradle
+++ b/palantir-java-format-native/build.gradle
@@ -56,8 +56,7 @@ graalvmNative {
             configurationFileDirectories.from(file('src/main/resources/META-INF/native-image'))
             buildArgs.addAll(
                     '-H:+UnlockExperimentalVMOptions',
-                    '-H:IncludeResourceBundles=com.sun.tools.javac.resources.compiler',
-                    '-H:IncludeResourceBundles=com.sun.tools.javac.resources.javac',
+                    '-H:+IncludeAllLocales',
                     '--no-fallback',
                     '--initialize-at-build-time=com.sun.tools.javac.file.Locations',
                     '-H:+ReportExceptionStackTraces',
@@ -69,12 +68,6 @@ graalvmNative {
     }
 }
 
-
-// The image requires parameters to be passed to; eg. gw nativeRun -Pargs=--palantir,-i,<file>
-tasks.named("nativeRun", org.graalvm.buildtools.gradle.tasks.NativeRunTask) {
-    runtimeArgs.addAll(project.hasProperty('appArgs') ? project.appArgs.split(',') : [])
-}
-
 if (Optional.ofNullable(System.getenv("CI")).isPresent()) {
     externalPublishing {
         publication('nativeImage') {
diff --git a/palantir-java-format-native/src/main/resources/META-INF/native-image/reachability-metadata.json b/palantir-java-format-native/src/main/resources/META-INF/native-image/reachability-metadata.json
index d647ee93e..b5d2dfafc 100644
--- a/palantir-java-format-native/src/main/resources/META-INF/native-image/reachability-metadata.json
+++ b/palantir-java-format-native/src/main/resources/META-INF/native-image/reachability-metadata.json
@@ -47,11 +47,11 @@
       "allDeclaredFields": true
     },
     {
-      "type": "com.google.common.collect.SingletonImmutableList",
+      "type": "com.google.common.collect.RegularImmutableList",
       "allDeclaredFields": true
     },
     {
-      "type": "com.google.common.collect.RegularImmutableList",
+      "type": "com.google.common.collect.SingletonImmutableList",
       "allDeclaredFields": true
     },
     {
@@ -164,26 +164,19 @@
       "glob": "META-INF/services/java.lang.System$LoggerFinder"
     },
     {
-      "glob": "com/sun/tools/javac/resources/compiler_en.properties"
-    },
-    {
-      "glob": "com/sun/tools/javac/resources/compiler_en_US.properties"
+      "glob": "com/sun/tools/javac/resources/**"
     },
     {
       "module": "jdk.compiler",
-      "glob": "com/sun/tools/javac/resources/compiler_en.properties"
-    },
-    {
-      "module": "jdk.compiler",
-      "glob": "com/sun/tools/javac/resources/compiler_en_US.properties"
+      "glob": "com/sun/tools/javac/resources/**"
     }
   ],
   "bundles": [
     {
-      "name": "com.sun.tools.javac.resources.compiler",
-      "locales": [
-        "en-US"
-      ]
+      "name": "com.sun.tools.javac.resources.compiler"
+    },
+    {
+      "name": "com.sun.tools.javac.resources.javac"
     }
   ],
   "jni": [


Reviews:
user: login: crogoz
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-18T13:00:16Z
user: login: crogoz
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T11:19:36Z
user: login: crogoz
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T11:19:38Z
user: login: CRogers
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-19T11:35:10Z

Review comments:
diff_hunk: @@ -78,6 +78,23 @@ void can_format_large_input_file(FormatterService formatterService) throws Forma
         });
     }
 
+    @ParameterizedTest
+    @MethodSource("getFormatters")
+    void no_replacements_for_invalid_input(FormatterService formatterService) throws FormatterException {
+        String input =
+                """
+            class Foo {
+
+            /* hello*/
+            public void main(     String    aaaa ) {
+                System.out.println("aaaaa"}; }
+            }
+        """;
+
+        assertThat(formatterService.getFormatReplacements(input, List.of(Range.open(0, input.length()))))
path: palantir-java-format-jdk-bootstrap/src/test/java/com/palantir/javaformat/bootstrap/FormatterServicesTest.java
user: login: crogoz
body: without this change, the issue is reproduced in the test
created_at: 2025-03-18T13:00:16Z
author_association: CONTRIBUTOR
diff_hunk: @@ -164,26 +164,19 @@
       "glob": "META-INF/services/java.lang.System$LoggerFinder"
     },
     {
-      "glob": "com/sun/tools/javac/resources/compiler_en.properties"
-    },
-    {
-      "glob": "com/sun/tools/javac/resources/compiler_en_US.properties"
+      "glob": "com/sun/tools/javac/resources/**"
     },
     {
       "module": "jdk.compiler",
-      "glob": "com/sun/tools/javac/resources/compiler_en.properties"
-    },
-    {
-      "module": "jdk.compiler",
-      "glob": "com/sun/tools/javac/resources/compiler_en_US.properties"
+      "glob": "com/sun/tools/javac/resources/**"
     }
   ],
   "bundles": [
     {
-      "name": "com.sun.tools.javac.resources.compiler",
path: palantir-java-format-native/src/main/resources/META-INF/native-image/reachability-metadata.json
user: login: crogoz
body: we shouldn't restrict the locales for the compiler bundle - by default we will include everything
created_at: 2025-03-19T11:19:36Z
author_association: CONTRIBUTOR
diff_hunk: @@ -69,12 +68,6 @@ graalvmNative {
     }
 }
 
-
-// The image requires parameters to be passed to; eg. gw nativeRun -Pargs=--palantir,-i,<file>
-tasks.named("nativeRun", org.graalvm.buildtools.gradle.tasks.NativeRunTask) {
path: palantir-java-format-native/build.gradle
user: login: crogoz
body: I don't think it makes sense to keep this here - I usually just run the native image directly
created_at: 2025-03-19T11:19:38Z
author_association: CONTRIBUTOR

PR comments:
user: login: changelog-app[bot]
created_at: 2025-03-18T12:46:14Z
body: ### Generate changelog in <changelog-dir>`changelog/@unreleased`</changelog-dir>
<details>
<summary>What do the change types mean?</summary>

- `feature`: A new feature of the service.
- `improvement`: An incremental improvement in the functionality or operation of the service.
- `fix`: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
- `break`: Has the potential to break consumers of this service's API, inclusive of both Palantir services
and external consumers of the service's API (e.g. customer-written software or integrations).
- `deprecation`: Advertises the intention to remove service functionality without any change to the
operation of the service itself.
- `manualTask`: Requires the possibility of manual intervention (running a script, eyeballing configuration,
performing database surgery, ...) at the time of upgrade for it to succeed.
- `migration`: A fully automatic upgrade migration task with no engineer input required.

_Note: only one type should be chosen._
</details>
<details>
<summary>How are new versions calculated?</summary>

- ❗The `break` and `manual task` changelog types will result in a major release!
- 🐛 The `fix` changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
- ✨ All others will result in a minor version release.
</details>

**Type**
<changelog-type>
- [ ] Feature
- [ ] Improvement
- [x] Fix
- [ ] Break
- [ ] Deprecation
- [ ] Manual task
- [ ] Migration
</changelog-type>

**Description**
<changelog-description>
Native image IncludeAllLocales and updates reachability-metadata's resources glob to include all entries under `com/sun/tools/javac/resources/**`
</changelog-description><changelog-links></changelog-links><changelog-tags></changelog-tags>

**Check the box to generate changelog(s)**
- [x] Generate changelog entry

author_association: NONE
user: login: autorelease3[bot]
created_at: 2025-03-19T11:35:22Z
body: Released [2.60.0](https://github.com/palantir/palantir-java-format/releases/tag/2.60.0)

author_association: NONE