Closed vsevel closed 3 years ago
You can likely get around the problem, by using @RegisterForReflection(targets=ArrayList.class)
.
@zakkak shouldn't GraalVM be able to handle serialization out of the box?
I forgot to mention that I had already:
@RegisterForReflection(serialization = true, targets = { ArrayList.class, String.class })
public class ReflectionConfig {
}
hello @zakkak what is the proper way to progress on this issue? should I create an issue directly on the graalvm project?
I think this is a bug in Quarkus. It looks like when serialization
is set to true
on the RegisterForReflection
annotation, the RegisterForReflectionBuildStep
only registers it for serialization and explicitly disables reflection registration. Specifically, this line https://github.com/quarkusio/quarkus/blob/main/core/deployment/src/main/java/io/quarkus/deployment/steps/RegisterForReflectionBuildStep.java#L68. Notice that if serialization is true
, it will call ReflectiveClassBuildItem.serializationClass(className)
which looks like:
public static ReflectiveClassBuildItem serializationClass(String... className) {
return new ReflectiveClassBuildItem(false, false, false, false, false, true, className);
}
Hi @vsevel sorry for the delay, I was on PTO. I 'll have a look at it (and #19942) this week and come back to you.
HI @zakkak np. hope you had some good time. note that @matthyx tested a pure java native serialization example, which works fine: https://github.com/matthyx/graalvm-serialization (with no reflection or serialization specific configuration). it appears that something is getting the array list constructors to get dropped. hope it rings some bells.
(with no reflection or serialization specific configuration)
FWIW that's not entirely true. https://github.com/matthyx/graalvm-serialization/blob/f0941a80c8fbca8c81a24c0b81799258a2223535/Dockerfile#L5 essentially generates the necessary configuration.
$ /opt/jvms/graalvm-ce-java11-21.2.0/bin/java -agentlib:native-image-agent=config-output-dir=META-INF/native-image HelloWorld
[toto, tutu, titi]
$ more META-INF/native-image/serialization-config.json
[
{
"name":"java.util.ImmutableCollections$ListN"
},
{
"name":"java.lang.String"
},
{
"name":"java.util.CollSer"
}
]
Without this the generated binary fails with:
$ rm -rf META-INF
$ /opt/jvms/graalvm-ce-java11-21.2.0/bin/native-image --no-fallback HelloWorld
...
$ ./helloworld
Exception in thread "main" java.lang.ClassNotFoundException: java.util.ImmutableCollections$ListN
at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:71)
at java.lang.Class.forName(DynamicHub.java:1319)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:756)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1995)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1862)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2169)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1679)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:493)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:451)
at HelloWorld.main(HelloWorld.java:19)
FWIW that's not entirely true.
Yes, I never said there wasn't one... but at least that's not something I had to write (or figure out).
I never said there wasn't one
Well I did ;) thanks for the precision @zakkak
Describe the bug
When trying to serialize an
ArrayList
in native, we get the following error:Looks similar to https://github.com/micronaut-projects/micronaut-redis/issues/194
Expected behavior
The list should be able to be serialized and un-serialized.
Actual behavior
It fails with the above exception.
How to Reproduce?
Reproducer:
curl http://localhost:8080/hello/serstring
=>Hello RESTEasy
curl http://localhost:8080/hello/serlist
=> exceptionOutput of
uname -a
orver
windows
Output of
java -version
openjdk 11.0.1-redhat 2018-10-16 LTS
GraalVM version (if different from Java)
Running Quarkus native-image plugin on GraalVM 21.1.0 Java 11 CE (Java Version 11.0.11+8-jvmci-21.1-b05)
Quarkus version or git rev
2.1.4.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Additional information
<quarkus.native.container-build>true</quarkus.native.container-build>