graal
graal copied to clipboard
[GR-54058] Serialization of float[] or other arrays is not supported in Native Image
-
OS: Centos 7.9
-
jdk version:
sdk install java 22.3.r17-nik
sdk use java 22.3.r17-nik
sdk default java 22.3.r17-nik
3.code: HelloWorld.java
import sun.reflect.ReflectionFactory;
import java.io.ObjectStreamClass;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class HelloWorld {
public static void main(String[] args) throws Exception{
Class clazz= float[].class;
Constructor c = java.lang.Object.class.getDeclaredConstructor((Class[]) null);
c = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(clazz, c);
System.out.println("Hello, Native World!");
}
}
serialization-config.json is follow:
[
{
"name": "[F"
},
{
"name": "float[]"
},
{
"name": "java.lang.Float[]"
},
{
"name": "java.lang.Float"
}
]
or :
{
"types": [
{
"name": "[F"
},
{
"name": "float[]"
},
{
"name": "java.lang.Float[]"
},
{
"name": "java.lang.Float"
}],
"lambdaCapturingTypes": [],
"proxies": []
}
- step: javac HelloWorld.java native-image HelloWorld --no-fallback -H:ReflectionConfigurationFiles=r.json -H:SerializationConfigurationFiles=serialization-config.json
Exception is as as follow:
[root@localhost example]# ./helloworld
Exception in thread "main" com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: [F (targetConstructorClass: java.lang.Object). Usually adding [F to serialization-config.json fixes the problem.
at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:92)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.serialize.SerializationSupport.getSerializationConstructorAccessor(SerializationSupport.java:143)
at [email protected]/jdk.internal.reflect.MethodAccessorGenerator.generateSerializationConstructor(MethodAccessorGenerator.java:61)
at [email protected]/jdk.internal.reflect.ReflectionFactory.generateConstructor(ReflectionFactory.java:463)
at [email protected]/jdk.internal.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:376)
at [email protected]/sun.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:100)
at HelloWorld.main(HelloWorld.java:13)
Hi. Can you please share more details about this issue? what version of GraalVM are you using? how did you create the native image? what OS are you using? And finally, share the steps we need to take to reproduce this issue.
@imgoby could you please try with Oracle GraalVM for JDK 17 (sdk install java 17.0.10-graal
), or CE? Maybe this issue was already fixed in that release.
I try to use this version: java 17.0.10-graal or version: java 17.0.9-graalce
the problem is the same.
@fniephaus @fernando-valdez Is there any ways?
Looks like your serialization-config.json
doesn't follow the JSON schema described in https://www.graalvm.org/latest/reference-manual/native-image/metadata/#serialization-metadata-in-json (types must be declared under the "types" key)
Something like this may work:
{
"types": [
{ "name": "[F" }
]
}
I tried this way before.It doesn't work. @mukel
@imgoby, can you please confirm if this is happening in the non-community edition? please try java 17.0.10-graal
instead of java 17.0.9-graalce
Yes, it is indeed。 neither java 17.0.10-graal or java 17.0.9-graalce,there is the same exception.
this is a small project,you can reproduce it:
https://github.com/imgoby/graalvm-array-serialization
Is there any progress?
I shared this issue with the native image team. Here is the internal ticket GR-54058