Skip to content

fix(java): Correct resolution of dependent/nested serializers in GraalVM#3532

Merged
chaokunyang merged 8 commits intoapache:mainfrom
rakow:fix/graalvm
Apr 1, 2026
Merged

fix(java): Correct resolution of dependent/nested serializers in GraalVM#3532
chaokunyang merged 8 commits intoapache:mainfrom
rakow:fix/graalvm

Conversation

@rakow
Copy link
Copy Markdown
Contributor

@rakow rakow commented Mar 31, 2026

Why?

GraalVM native-image serializer codegen can leak GraalvmSerializerHolder into generated serializer constructor paths. When serializer resolution returns serializer.getClass() instead of the underlying generated serializer class, dependent generated codecs can later fail with

java.lang.ClassCastException: […]Codec_0 cannot be cast to org.apache.fory.util.GraalvmSupport$GraalvmSerializerHolder at org.apache.fory.Fory.processSerializationError(Fory.java:377)

or

java.lang.RuntimeException: Class […] is not registered

This PR fixes that resolver behavior and adds regression tests.

What does this PR do?

  • Fixes ClassResolver to unwrap holder-backed serializers via getGraalvmSerializerClass(...) when resolving serializer classes.
  • Fixes TypeResolver to query the iterated resolver, not this, when checking the GraalVM registry, and to unwrap holder-backed serializers there as well.
  • Adds a new GraalVM integration example, CompatibleDependentSerializerThreadSafeExample, that features generated serializer to depend on another

Related issues

None.

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, I included the standardized AI Usage Disclosure block below.
  • If yes, I can explain and defend all important changes without AI help.
  • If yes, I reviewed AI-assisted code changes line by line before submission.
  • If yes, I ran adequate human verification and recorded evidence.
  • If yes, I added/updated tests and specs where required.
  • If yes, I validated protocol/performance impacts with evidence when applicable.
  • If yes, I verified licensing and provenance compliance.
AI Usage Disclosure
- substantial_ai_assistance: yes
- scope: code drafting, regression tests
- affected_files_or_subsystems: java/fory-core resolver logic; integration_tests/graalvm_tests GraalVM regression example
- human_verification: contributor reproduced the error using tests and than verified the fix works as expected, contributor reviewed changes line by line  
- performance_verification: no intended user-facing performance change and no dedicated benchmark was run
- provenance_license_confirmation: Apache-2.0-compatible provenance confirmed; no incompatible third-party code introduced

Benchmark

N/A. No dedicated benchmark was run for this change. The validation for this PR is targeted regression coverage for GraalVM build-time serializer resolution and GraalVM integration behavior.

@rakow rakow requested a review from chaokunyang as a code owner March 31, 2026 14:20
Copy link
Copy Markdown
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chaokunyang chaokunyang merged commit e85b857 into apache:main Apr 1, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants