oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.39k stars 1.64k forks source link

[native-image] Runtime error when using java.lang.reflect.Array in library #9603

Open tomgelu opened 2 months ago

tomgelu commented 2 months ago

Describe the issue

Native application throws com.oracle.svm.core.jdk.UnsupportedFeatureError in runtime, while using java.lang.reflect.Array to generate a new instance of an object encapsulated in a generic. Adding a type hint did not solve the issue.

The error is observed only when such operation is inside a dependency. Extracting the code from the library and putting it into the application being compiled, seem to trigger a proper reflection autoconfiguration.

It would be interesting to understand how that specific reflection hit can be provided in the native-image configuration.

Also it's crashing when using Jakarta RESTful WS API but not when using QuarkusApplication. Working example commented in the repo.

Steps to reproduce the issue

  1. git clone git@github.com:tomgelu/native-image-issue.git
  2. cd native-image-issue
  3. docker build -f src/main/docker/Dockerfile.native-micro -t native-image-issue:test .
  4. docker run -p 8080:8080 native-image-issue:test
  5. curl --request POST --url http://localhost:8080/test

More details

at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:121)
at java.base@21.0.2/java.lang.reflect.Array.multiNewArray(Array.java:409)
at java.base@21.0.2/java.lang.reflect.Array.newInstance(Array.java:114)
at org.hipparchus.util.MathArrays.buildArray(MathArrays.java:1628)
at org.hipparchus.geometry.euclidean.threed.FieldRotation.<init>(FieldRotation.java:247)
at org.orekit.frames.LOFType$3.rotationFromInertial(LOFType.java:151) 
fernando-valdez commented 2 months ago

Thanks for reporting this issue. I will take a look at the repreducer and will let you know if I have any questions