Skip to content

[Native Image] "native-image-agent" fails to generate complete reflection for classes without default constructor when using gson for de-serialization #12770

@Sasuke214

Description

@Sasuke214

Describe the Issue

Issue

The problem is when i generate a native image and run it, it throws below error:
java.lang.IllegalArgumentException: Type org.example.dtos.SSOGetTokenResponse is instantiated reflectively but was never registered. Register the type by adding "unsafeAllocated" for the type in rechability-metadata.json

currently as a workaround, i have added "unsafeAllocated" to generated reflection config manually and it works post that but would be awesome if we can figure out and fix it in the tool itself somehow

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

➜ graalvm-demo git:(main) ✗ java --version
java 25.0.1 2025-10-21 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 25.0.1+8.1 (build 25.0.1+8-LTS-jvmci-b01)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 25.0.1+8.1 (build 25.0.1+8-LTS-jvmci-b01, mixed mode, sharing)

Operating System and Version

Darwin Kernel Version 24.4.0: Fri Apr 11 18:32:50 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6041 arm64

Build Command

Clone the repo https://github.com/Sasuke214/graalvm-demo
Run sdk use java 25.0.1-graal
Run ./mvnw -Pnative -DskipTests native:compile
Run ./target/Graal-JS

Expected Behavior

Generates complete reflection for the provided class

Actual Behavior

Generates reflection for the provided class but doesn't have "unsafeAllocated" or any way to instanciate that class

Steps to Reproduce

  1. Clone the repo https://github.com/Sasuke214/graalvm-demo
  2. Run sdk use java 25.0.1-graal
  3. Run ./mvnw -Pnative -DskipTests native:compile
  4. Run ./target/Graal-JS

Additional Context

No response

Build Log Output and Error Messages

java.lang.IllegalArgumentException: Type org.example.dtos.SSOGetTokenResponse is instantiated reflectively but was never registered. Register the type by adding "unsafeAllocated" for the type in rechability-metadata.json.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions