Skip to content

fix(java): copy non-serializable JDK objects by reference - #4179

Open
itsCodeTide wants to merge 1 commit into
apache:mainfrom
itsCodeTide:fix/java-copy-nonserializable
Open

itsCodeTide wants to merge 1 commit into
apache:mainfrom
itsCodeTide:fix/java-copy-nonserializable

Conversation

@itsCodeTide

@itsCodeTide itsCodeTide commented Oct 14, 2026 •

Copy link
Copy Markdown

Why?

Fory.copy currently fails when an object graph contains a non-serializable JDK object such as java.lang.Package. Copy and serialization share serializer lookup, so the serializability guard rejects the type before the copy path can handle it.

What does this PR do?

  • Routes non-serializable JDK types through a serializer that preserves the object by reference during copy.
  • Keeps binary serialization unsupported for those types; serializer reads and writes still fail.
  • Adds tests for direct and nested Package copies and for serialization still failing.

Related issues

Fixes #2941

Related: #3797 is an open PR for the same issue with a field-copy approach. This PR instead preserves the opaque JDK object by identity.

AI Contribution Checklist

  • Substantial AI assistance was used: yes
  • Included an AI Usage Disclosure below.
  • I can explain and defend the changes.
  • I reviewed the changes line by line and completed my self-review.
  • Two fresh AI reviews ran on commit 029ca6a834e1ca71c3c335594611b28c16740088; neither found actionable issues.
  • No actionable AI review comments needed fixes or another review round.
  • I completed human verification and reviewed the results.
  • I confirmed provenance and licensing.

AI Usage Disclosure

  • substantial_ai_assistance: yes
  • scope: design discussion, code, and regression tests
  • affected_files_or_subsystems: Java fory-core resolver, serializer, GraalVM serializer metadata, and copy tests
  • ai_review: Two fresh read-only reviews of commit 029ca6a834e1ca71c3c335594611b28c16740088 reported no actionable findings.
  • ai_review_artifacts:
    • Fory-guided reviewer /root/fory_review, reviewed 029ca6a834e1ca71c3c335594611b28c16740088: “No actionable findings.”
    • Independent reviewer /root/independent_review, reviewed 029ca6a834e1ca71c3c335594611b28c16740088: “No actionable correctness, edge-case, maintainability, or test-quality findings.”
  • human_verification: The agent ran the focused ForyCopyTest (12 passed), Spotless (passed), and Checkstyle (0 violations). The complete fory-core suite ran 2,348 tests and had 17 failures on JDK 24, in collection, ObjectStream, and URL-copy cases; these have not been checked against the base branch. Contributor review is still required.
  • performance_verification: N/A; no benchmark was run.
  • provenance_license_confirmation: Please confirm before checking this item; the new code uses the project’s standard Apache license header and introduces no third-party code.

Does this PR introduce any user-facing change?

Fory.copy now succeeds for graphs containing non-serializable JDK objects by retaining those objects by reference.

  • Public API change
  • Binary protocol compatibility change

Benchmark

N/A

This branch has not been deployed

No deployments
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.

[Java] support copy non-serializable objects such as java.lang.Package

1 participant