Skip to content

[Java][Native Image] ObjectCreator sometimes produces Object under GraalVM 25 #2697

@gudzpoz

Description

@gudzpoz

Search before asking

  • I had searched in the issues and found no similar issues.

Version

OS: ArchLinux (6.16.7-zen1-1-zen)
Fory: 'org.apache.fory:fory-core:0.13.0-SNAPSHOT' (Sep 30)
JDK: GraalVM CE 25+37.1 (build 25+37-jvmci-b01)

Component(s)

Java

Minimal reproduce step

See https://github.com/gudzpoz/fory-native-image-reproducer/blob/private-constructor/app/src/main/java/org/example/App.java .

$ git clone https://github.com/gudzpoz/fory-native-image-reproducer.git
$ git checkout private-constructor
$ ./gradlew run # pass
$ ./gradlew nativeCompile
$ app/build/native/nativeCompile/test
Error: Exception in thread "main" org.apache.fory.exception.DeserializationException: Deserialize failed, read objects are: [org.example.App@653b6657, java.lang.Object@2a34e425]
	at org.apache.fory.util.ExceptionUtils.handleReadFailed(ExceptionUtils.java:63)
	at org.apache.fory.Fory.deserialize(Fory.java:889)
	at org.apache.fory.Fory.deserialize(Fory.java:785)
	at org.example.App.main(App.java:32)
	at java.base@25/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to org.example.App$AbstractClass
	at org.example.AppForyRefCodec_0.read(AppForyRefCodec_0.java:73)
	at org.apache.fory.Fory.readDataInternal(Fory.java:1046)
	at org.apache.fory.Fory.readRef(Fory.java:931)
	at org.apache.fory.Fory.deserialize(Fory.java:885)
	... 3 more

Here is the GitHub action run reproducing the issue: https://github.com/gudzpoz/fory-native-image-reproducer/actions/runs/18224046965/job/51890537453 . (The "Test" step contains the failing stack trace.)

What did you expect to see?

The test should pass.

What did you see instead?

$ app/build/native/nativeCompile/test
Error: Exception in thread "main" org.apache.fory.exception.DeserializationException: Deserialize failed, read objects are: [org.example.App@653b6657, java.lang.Object@2a34e425]
	at org.apache.fory.util.ExceptionUtils.handleReadFailed(ExceptionUtils.java:63)
	at org.apache.fory.Fory.deserialize(Fory.java:889)
	at org.apache.fory.Fory.deserialize(Fory.java:785)
	at org.example.App.main(App.java:32)
	at java.base@25/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to org.example.App$AbstractClass
	at org.example.AppForyRefCodec_0.read(AppForyRefCodec_0.java:73)
	at org.apache.fory.Fory.readDataInternal(Fory.java:1046)
	at org.apache.fory.Fory.readRef(Fory.java:931)
	at org.apache.fory.Fory.deserialize(Fory.java:885)
	... 3 more

Anything Else?

This seems to be related to the private constructor(s). Changing private ConcreteClass(int i) to protected ConcreteClass(int i) solves the issue. Also ObjectCreator does not seem to handle parent constructors with arguments currently?

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions