From f0a9748d045d54f3ebb78511bafc358cea6feb31 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 4 Feb 2026 01:02:41 -0800 Subject: [PATCH 1/3] Update workaround for JDK-8372948 The upstream change is removing the overload of `newParser`. PiperOrigin-RevId: 865273867 --- .../google/googlejavaformat/java/Trees.java | 59 ++++++------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/core/src/main/java/com/google/googlejavaformat/java/Trees.java b/core/src/main/java/com/google/googlejavaformat/java/Trees.java index faca6ff86..ad8201bae 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/Trees.java +++ b/core/src/main/java/com/google/googlejavaformat/java/Trees.java @@ -179,13 +179,12 @@ public String getCharContent(boolean ignoreEncodingErrors) { JavacParser parser; try { parser = - (JavacParser) - NEW_PARSER_HANDLE.invokeExact( - parserFactory, - (CharSequence) javaInput, - /* keepDocComments */ true, - /* keepEndPos */ true, - /* keepLineMap */ true); + newParser( + parserFactory, + javaInput, + /* keepDocComments= */ true, + /* keepEndPos= */ true, + /* keepLineMap= */ true); } catch (Throwable e) { Throwables.throwIfUnchecked(e); throw new AssertionError(e); @@ -195,6 +194,19 @@ public String getCharContent(boolean ignoreEncodingErrors) { return unit; } + private static JavacParser newParser( + ParserFactory parserFactory, + CharSequence source, + boolean keepDocComments, + boolean keepEndPos, + boolean keepLineMap) { + if (END_POS_TABLE_CLASS != null) { + return parserFactory.newParser(source, keepDocComments, keepEndPos, keepLineMap); + } + return parserFactory.newParser( + source, keepDocComments, keepLineMap, /* parseModuleInfo */ false); + } + private static boolean errorDiagnostic(Diagnostic input) { if (input.getKind() != Diagnostic.Kind.ERROR) { return false; @@ -215,39 +227,6 @@ private static boolean errorDiagnostic(Diagnostic input) { } } - private static final MethodHandle NEW_PARSER_HANDLE = getNewParserHandle(); - - private static MethodHandle getNewParserHandle() { - MethodHandles.Lookup lookup = MethodHandles.lookup(); - if (END_POS_TABLE_CLASS == null) { - try { - // (parserFactory, input, keepDocComments, keepEndPos, keepLineMap) -> - // parserFactory.newParser(input, keepDocComments, keepLineMap) - return MethodHandles.dropArguments( - lookup.findVirtual( - ParserFactory.class, - "newParser", - MethodType.methodType( - JavacParser.class, CharSequence.class, boolean.class, boolean.class)), - 3, - boolean.class); - } catch (ReflectiveOperationException e) { - throw new LinkageError(e.getMessage(), e); - } - } - try { - // (parserFactory, input, keepDocComments, keepEndPos, keepLineMap) -> - // parserFactory.newParser(input, keepDocComments, keepEndPos, keepLineMap) - return lookup.findVirtual( - ParserFactory.class, - "newParser", - MethodType.methodType( - JavacParser.class, CharSequence.class, boolean.class, boolean.class, boolean.class)); - } catch (ReflectiveOperationException e) { - throw new LinkageError(e.getMessage(), e); - } - } - private static final MethodHandle GET_END_POS_HANDLE = getEndPosMethodHandle(); private static MethodHandle getEndPosMethodHandle() { From ff157e3e4655c695b59028bb2a2f322e992eae95 Mon Sep 17 00:00:00 2001 From: Claudio Nave Date: Wed, 4 Feb 2026 11:29:34 -0800 Subject: [PATCH 2/3] Fix reflection errors during native execution Hi, after updating to the new version 1.34.0 I'm receiving this error running the native binary: ``` error: no such method: com.sun.tools.javac.tree.JCTree.getEndPosition(EndPosTable)int/invokeVirtual java.lang.LinkageError: no such method: com.sun.tools.javac.tree.JCTree.getEndPosition(EndPosTable)int/invokeVirtual at com.google.googlejavaformat.java.Trees.getEndPosMethodHandle(Trees.java:278) at com.google.googlejavaformat.java.Trees.(Trees.java:251) at com.google.googlejavaformat.java.Formatter.format(Formatter.java:104) at com.google.googlejavaformat.java.Formatter.getFormatReplacements(Formatter.java:214) at com.google.googlejavaformat.java.Formatter.formatSource(Formatter.java:188) at com.google.googlejavaformat.java.FormatFileCallable.call(FormatFileCallable.java:75) at com.google.googlejavaformat.java.FormatFileCallable.call(FormatFileCallable.java:29) at java.base@25.0.2/java.util.concurrent.FutureTask.run(FutureTask.java:328) at java.base@25.0.2/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545) at java.base@25.0.2/java.util.concurrent.FutureTask.run(FutureTask.java:328) at java.base@25.0.2/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090) at java.base@25.0.2/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614) at java.base@25.0.2/java.lang.Thread.runWith(Thread.java:1487) at java.base@25.0.2/java.lang.Thread.run(Thread.java:1474) at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:832) at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:808) Caused by: java.lang.NoSuchMethodException: no such method: com.sun.tools.javac.tree.JCTree.getEndPosition(EndPosTable)int/invokeVirtual at java.base@25.0.2/java.lang.invoke.MemberName.makeAccessException(MemberName.java:910) at java.base@25.0.2/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:989) at java.base@25.0.2/java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:3591) at java.base@25.0.2/java.lang.invoke.MethodHandles$Lookup.findVirtual(MethodHandles.java:2610) at com.google.googlejavaformat.java.Trees.getEndPosMethodHandle(Trees.java:269) ... 15 more Caused by: java.lang.NoSuchMethodError: com.sun.tools.javac.tree.JCTree.getEndPosition(com.sun.tools.javac.tree.EndPosTable) at org.graalvm.nativeimage.builder/com.oracle.svm.core.methodhandles.Util_java_lang_invoke_MethodHandleNatives.resolve(Target_java_lang_invoke_MethodHandleNatives.java:352) at java.base@25.0.2/java.lang.invoke.MethodHandleNatives.resolve(MethodHandleNatives.java:208) at java.base@25.0.2/java.lang.invoke.MemberName$Factory.resolve(MemberName.java:120) at java.base@25.0.2/java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:986) ... 18 more ``` It's caused by https://github.com/google/google-java-format/commit/4a15b1b9a4063a8ec2958ba3fc0924d1be046b93 that introduced new reflection invocations that the native build process isn't able to pick up. Following [this guide](https://www.graalvm.org/latest/reference-manual/native-image/metadata/AutomaticMetadataCollection/) I generated an updated config file to fix the problem. The config file name changed in Graal 23, but it's only used during build time so it shouldn't matter that much. With this fix everything works fine (at least for my case :grin:). Fixes #1327 COPYBARA_INTEGRATE_REVIEW=https://github.com/google/google-java-format/pull/1327 from EvaristeGalois11:fix-graalvm 6bdd7cd27aea5b8132f16b5ac2fd4f0ab0909273 PiperOrigin-RevId: 865501302 --- .../native-image/reachability-metadata.json | 106 ++++++++++++++++++ .../META-INF/native-image/reflect-config.json | 6 - 2 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 core/src/main/resources/META-INF/native-image/reachability-metadata.json delete mode 100644 core/src/main/resources/META-INF/native-image/reflect-config.json diff --git a/core/src/main/resources/META-INF/native-image/reachability-metadata.json b/core/src/main/resources/META-INF/native-image/reachability-metadata.json new file mode 100644 index 000000000..1047784a0 --- /dev/null +++ b/core/src/main/resources/META-INF/native-image/reachability-metadata.json @@ -0,0 +1,106 @@ +{ + "reflection": [ + { + "type": "com.google.googlejavaformat.java.JavacTokens$CommentSavingTokenizer" + }, + { + "type": "com.sun.source.tree.CaseTree" + }, + { + "type": "com.sun.source.tree.ImportTree", + "methods": [ + { + "name": "isModule", + "parameterTypes": [] + } + ] + }, + { + "type": "com.sun.tools.javac.parser.JavaTokenizer" + }, + { + "type": "com.sun.tools.javac.parser.ParserFactory", + "methods": [ + { + "name": "newParser", + "parameterTypes": [ + "java.lang.CharSequence", + "boolean", + "boolean", + "boolean" + ] + } + ] + }, + { + "type": "com.sun.tools.javac.parser.UnicodeReader", + "methods": [ + { + "name": "getRawCharacters", + "parameterTypes": [ + "int", + "int" + ] + } + ] + }, + { + "type": "com.sun.tools.javac.tree.EndPosTable" + }, + { + "type": "com.sun.tools.javac.tree.JCTree", + "methods": [ + { + "name": "getEndPosition", + "parameterTypes": [ + "com.sun.tools.javac.tree.EndPosTable" + ] + } + ] + }, + { + "type": "com.sun.tools.javac.tree.JCTree$JCCompilationUnit", + "fields": [ + { + "name": "endPositions" + } + ] + }, + { + "type": "com.sun.tools.javac.tree.JCTree$JCImport", + "methods": [ + { + "name": "getQualifiedIdentifier", + "parameterTypes": [] + } + ] + }, + { + "type": "com.sun.tools.javac.util.Log$DeferredDiagnosticHandler", + "methods": [ + { + "name": "", + "parameterTypes": [ + "com.sun.tools.javac.util.Log" + ] + }, + { + "name": "getDiagnostics", + "parameterTypes": [] + } + ] + }, + { + "type": "java.lang.Boolean", + "jniAccessible": true, + "methods": [ + { + "name": "getBoolean", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/core/src/main/resources/META-INF/native-image/reflect-config.json b/core/src/main/resources/META-INF/native-image/reflect-config.json deleted file mode 100644 index 2c6580345..000000000 --- a/core/src/main/resources/META-INF/native-image/reflect-config.json +++ /dev/null @@ -1,6 +0,0 @@ -[ - { - "name": "com.sun.tools.javac.parser.UnicodeReader", - "allDeclaredMethods": true - } -] From 64ee627337507dca8953da3771413fd81c96ec50 Mon Sep 17 00:00:00 2001 From: cushon Date: Wed, 4 Feb 2026 19:33:38 +0000 Subject: [PATCH 3/3] Release google-java-format 1.34.1 --- core/pom.xml | 2 +- eclipse_plugin/META-INF/MANIFEST.MF | 2 +- eclipse_plugin/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 3b106cf71..390f5c79b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -22,7 +22,7 @@ com.google.googlejavaformat google-java-format-parent - HEAD-SNAPSHOT + 1.34.1 google-java-format diff --git a/eclipse_plugin/META-INF/MANIFEST.MF b/eclipse_plugin/META-INF/MANIFEST.MF index 4170ad643..9676df6a9 100644 --- a/eclipse_plugin/META-INF/MANIFEST.MF +++ b/eclipse_plugin/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: google-java-format Bundle-SymbolicName: google-java-format-eclipse-plugin;singleton:=true Bundle-Vendor: Google -Bundle-Version: 1.31.0 +Bundle-Version: 1.34.1 Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.eclipse.jdt.core;bundle-version="3.10.0", org.eclipse.jface, diff --git a/eclipse_plugin/pom.xml b/eclipse_plugin/pom.xml index a5d8c23ae..59c49783f 100644 --- a/eclipse_plugin/pom.xml +++ b/eclipse_plugin/pom.xml @@ -22,7 +22,7 @@ com.google.googlejavaformat google-java-format-eclipse-plugin eclipse-plugin - 1.31.0 + 1.34.1 Google Java Format Plugin for Eclipse 4.5+ diff --git a/pom.xml b/pom.xml index 46306c196..7fc046bf7 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ com.google.googlejavaformat google-java-format-parent pom - HEAD-SNAPSHOT + 1.34.1 core