Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-57707] native-image-agent omits String[] from "serialization" when using newConstructorForSerialization #9581

Open
Karm opened this issue Aug 28, 2024 · 3 comments
Assignees

Comments

@Karm
Copy link
Contributor

Karm commented Aug 28, 2024

As I was looking at #8509 (comment) using native-agent to generate serialization config, it occurred to me that while e.g. both java.lang.Short[] and java.lang.String[][] get generated in the reachability-metadata.json, the java.lang.String[] is not added and has to be added manually. It's not a new thing though, I can see it both with older graalvm-community-jdk21u and with the very latest graalvm-community-java24.

How to reproduce

Using this source Main.java.zip
TL;DR:

        Class[] arrayTypes = new Class[] {
...
                Short[][].class,
                String[].class,
                String[][].class,
...
        };
        for (int i = 0; i < arrayTypes.length; i++) {
            Constructor<?> cons = java.lang.Object.class.getDeclaredConstructor((Class[]) null);
            cons = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(arrayTypes[i], cons);
            System.out.println(cons.getParameterCount());
            Object o = Array.newInstance(arrayTypes[i].getComponentType(), 0);
            System.out.println(o.getClass().descriptorString());
        }
$ native-image --version
native-image 24 2025-03-18
GraalVM Runtime Environment GraalVM CE 24-dev+12.1 (build 24+12-jvmci-b01)
Substrate VM GraalVM CE 24-dev+12.1 (build 24+12, serial gc)

$ java --version
openjdk 24 2025-03-18
OpenJDK Runtime Environment GraalVM CE 24-dev+12.1 (build 24+12-jvmci-b01)
OpenJDK 64-Bit Server VM GraalVM CE 24-dev+12.1 (build 24+12-jvmci-b01, mixed mode, sharing)

$ unzip Main.java.zip

$ javac Main.java

$ java -agentlib:native-image-agent=config-output-dir=AGENT Main

$ native-image -ea --no-fallback --link-at-build-time -H:ConfigurationFileDirectories=./AGENT Main

$ ./main
...
Exception in thread "main" com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: [Ljava.lang.String; (targetConstructorClass: java.lang.Object). Usually adding [Ljava.lang.String; to serialization-config.json fixes the problem.
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:121)
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.serialize.SerializationSupport.getSerializationConstructorAccessor(SerializationSupport.java:205)
    at java.base@24/jdk.internal.reflect.SerializationConstructorAccessorGenerator.generateSerializationConstructor(SerializationConstructorAccessorGenerator.java:53)
    at java.base@24/jdk.internal.reflect.ReflectionFactory.generateConstructor(ReflectionFactory.java:340)
    at java.base@24/jdk.internal.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:253)
    at jdk.unsupported@24/sun.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:100)
    at Main.main(Main.java:83)
    at java.base@24/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

When I edit the AGENT/reachability-metadata.json file as suggested by the helpful message:

  {
    "type": "java.lang.Short[][]",
    "customTargetConstructorClass": "java.lang.Object"
  },
+ {
+   "type": "java.lang.String[]",
+   "customTargetConstructorClass": "java.lang.Object"
+ },
  {
    "type": "java.lang.String[][]",
    "customTargetConstructorClass": "java.lang.Object"
  },

and run the build again, it works.

Is this expected of the native agent?

(@zakkak FYI)

@fernando-valdez fernando-valdez self-assigned this Aug 29, 2024
@fernando-valdez fernando-valdez changed the title native-image-agent omits String[] from "serialization" when using newConstructorForSerialization [GR-57707] native-image-agent omits String[] from "serialization" when using newConstructorForSerialization Aug 29, 2024
@fernando-valdez
Copy link
Member

Thanks for reporting this issue. Created GR-57707 for internal tracking

@zakkak
Copy link
Collaborator

zakkak commented Aug 29, 2024

cc @vjovanov

@vjovanov vjovanov assigned vjovanov and unassigned fernando-valdez Aug 30, 2024
@vjovanov
Copy link
Member

Not expected behavior, I will look into this early next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants