Skip to content

Commit ff157e3

Browse files
EvaristeGalois11google-java-format Team
authored andcommitted
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.<clinit>(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 4a15b1b 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 😁). Fixes #1327 COPYBARA_INTEGRATE_REVIEW=#1327 from EvaristeGalois11:fix-graalvm 6bdd7cd PiperOrigin-RevId: 865501302
1 parent f0a9748 commit ff157e3

File tree

2 files changed

+106
-6
lines changed

2 files changed

+106
-6
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"reflection": [
3+
{
4+
"type": "com.google.googlejavaformat.java.JavacTokens$CommentSavingTokenizer"
5+
},
6+
{
7+
"type": "com.sun.source.tree.CaseTree"
8+
},
9+
{
10+
"type": "com.sun.source.tree.ImportTree",
11+
"methods": [
12+
{
13+
"name": "isModule",
14+
"parameterTypes": []
15+
}
16+
]
17+
},
18+
{
19+
"type": "com.sun.tools.javac.parser.JavaTokenizer"
20+
},
21+
{
22+
"type": "com.sun.tools.javac.parser.ParserFactory",
23+
"methods": [
24+
{
25+
"name": "newParser",
26+
"parameterTypes": [
27+
"java.lang.CharSequence",
28+
"boolean",
29+
"boolean",
30+
"boolean"
31+
]
32+
}
33+
]
34+
},
35+
{
36+
"type": "com.sun.tools.javac.parser.UnicodeReader",
37+
"methods": [
38+
{
39+
"name": "getRawCharacters",
40+
"parameterTypes": [
41+
"int",
42+
"int"
43+
]
44+
}
45+
]
46+
},
47+
{
48+
"type": "com.sun.tools.javac.tree.EndPosTable"
49+
},
50+
{
51+
"type": "com.sun.tools.javac.tree.JCTree",
52+
"methods": [
53+
{
54+
"name": "getEndPosition",
55+
"parameterTypes": [
56+
"com.sun.tools.javac.tree.EndPosTable"
57+
]
58+
}
59+
]
60+
},
61+
{
62+
"type": "com.sun.tools.javac.tree.JCTree$JCCompilationUnit",
63+
"fields": [
64+
{
65+
"name": "endPositions"
66+
}
67+
]
68+
},
69+
{
70+
"type": "com.sun.tools.javac.tree.JCTree$JCImport",
71+
"methods": [
72+
{
73+
"name": "getQualifiedIdentifier",
74+
"parameterTypes": []
75+
}
76+
]
77+
},
78+
{
79+
"type": "com.sun.tools.javac.util.Log$DeferredDiagnosticHandler",
80+
"methods": [
81+
{
82+
"name": "<init>",
83+
"parameterTypes": [
84+
"com.sun.tools.javac.util.Log"
85+
]
86+
},
87+
{
88+
"name": "getDiagnostics",
89+
"parameterTypes": []
90+
}
91+
]
92+
},
93+
{
94+
"type": "java.lang.Boolean",
95+
"jniAccessible": true,
96+
"methods": [
97+
{
98+
"name": "getBoolean",
99+
"parameterTypes": [
100+
"java.lang.String"
101+
]
102+
}
103+
]
104+
}
105+
]
106+
}

core/src/main/resources/META-INF/native-image/reflect-config.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)