graal icon indicating copy to clipboard operation
graal copied to clipboard

[GR-54058] Serialization of float[] or other arrays is not supported in Native Image

Open imgoby opened this issue 11 months ago • 10 comments

  1. OS: Centos 7.9

  2. 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": []
}
  1. 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)


imgoby avatar Feb 29 '24 03:02 imgoby

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.

fernando-valdez avatar Mar 01 '24 02:03 fernando-valdez

@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.

fniephaus avatar Mar 01 '24 17:03 fniephaus

I try to use this version: java 17.0.10-graal or version: java 17.0.9-graalce

the problem is the same.

1709343446916

imgoby avatar Mar 02 '24 01:03 imgoby

@fniephaus @fernando-valdez Is there any ways?

imgoby avatar Mar 04 '24 01:03 imgoby

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" }
  ]
}

mukel avatar Mar 04 '24 07:03 mukel

I tried this way before.It doesn't work. @mukel

imgoby avatar Mar 04 '24 08:03 imgoby

@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

fernando-valdez avatar Mar 04 '24 19:03 fernando-valdez

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

imgoby avatar Mar 05 '24 01:03 imgoby

Is there any progress?

imgoby avatar May 07 '24 01:05 imgoby

I shared this issue with the native image team. Here is the internal ticket GR-54058

fernando-valdez avatar May 14 '24 02:05 fernando-valdez