zakkak commented on issue #4148:
URL: https://github.com/apache/camel-quarkus/issues/4148#issuecomment-1270044470
> @zakkak coul you elaborate on "not getting registered properly" ? What's
happening?
After looking a bit more into it, the issue is the following.
When the class name starts with `java.` gizmo gets the class directly (not
through reflection):
```java
private static void
registerClass35(org.graalvm.nativeimage.hosted.Feature.BeforeAnalysisAccess
var0) {
try {
Collections.EmptyList.class.getDeclaredConstructors();
Collections.EmptyList.class.getDeclaredMethods();
Collections.EmptyList.class.getDeclaredFields();
Class[] var1 = new Class[]{Collections.EmptyList.class};
RuntimeReflection.register(var1);
registerSerializationForClass(Collections.EmptyList.class);
} catch (Throwable var2) {
}
}
```
However, `Collections.EmptyList` is `private`, as a result this is not going
to work. Note here that we don't see any error due to
https://github.com/quarkusio/quarkus/issues/26162. The actual exception is:
```
java.lang.IllegalAccessError: failed to access class
java.util.Collections$EmptyList from class io.quarkus.runner.Feature
(java.util.Collections$EmptyList is in module java.base of loader 'bootstrap';
io.quarkus.runner.Feature is in unnamed module of loader
com.oracle.svm.hosted.NativeImageClassLoaderSupport$ClassPathClassLoader
@6d4b1c02)
at io.quarkus.runner.Feature.registerClass35(Unknown Source)
at io.quarkus.runner.Feature.beforeAnalysis(Unknown Source)
at
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$9(NativeImageGenerator.java:722)
at
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:78)
at
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:722)
at
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:564)
at
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:521)
at
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
at
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
at
org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
```
In contrast when registering a class that is not under `java.` the register
method uses `Class.forName` which works for private methods as well and looks
like this:
```java
private static void
registerClass0(org.graalvm.nativeimage.hosted.Feature.BeforeAnalysisAccess
var0) {
try {
ClassLoader var1 =
Thread.currentThread().getContextClassLoader();
Class var2 =
Class.forName("org.apache.commons.pool2.impl.DefaultEvictionPolicy",
(boolean)0, var1);
Constructor[] var4 = var2.getDeclaredConstructors();
var2.getDeclaredMethods();
var2.getDeclaredFields();
Class[] var3 = new Class[]{var2};
RuntimeReflection.register(var3);
RuntimeReflection.register((Executable[])var4);
} catch (Throwable var5) {
}
}
```
So I think that we either need to drop the `java.` prefix optimization from
gizmo or start checking if the class is private or not as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]