Skip to content

Conversation

@chaokunyang
Copy link
Collaborator

@chaokunyang chaokunyang commented Dec 29, 2025

Why?

Fix GitHub issue #2695: Abstract Class Corner Cases in Fory Serialization

Two problems were identified:

  1. Abstract Object Arrays: Serializing arrays with abstract component types (e.g., AbstractBase[]) would fail during ensureSerializersCompiled() because abstract types were incorrectly flagged as non-serializable.
  2. Abstract Enums: Enums with abstract methods (where each enum value is an anonymous inner class) would throw InsecureException because the enum value classes (e.g., AbstractEnum$1) were not recognized as secure.

What does this PR do?

1. Fix TypeResolver.isSerializable()

  • Check for enums before checking if abstract - enums are always serializable even if they have abstract methods.

2. Fix ClassResolver.isSecure()

  • For enum value classes (anonymous inner classes of abstract enums), check if the declaring enum class is secure instead of requiring the inner class itself to be registered.

3. Fix ClassResolver.createSerializer()

  • For enum value classes, reuse the serializer from the declaring enum class instead of creating a new one. This is more efficient and avoids polluting the class registry.

4. Fix ClassResolver.ensureSerializersCompiled()

  • For abstract arrays, check if the component type is serializable before trying to create a serializer.
  • For GraalVM builds, also create and cache serializers for enum value classes when processing abstract enums.

5. Add comprehensive tests

  • Unit tests in ClassResolverTest for abstract enum serialization and abstract object array serialization.
  • GraalVM integration test AbstractClassExample that tests abstract enums, abstract enum arrays, abstract object arrays, and containers with abstract types.

Related issues

Closes #2695

Does this PR introduce any user-facing change?

No user-facing API changes. Users can now serialize:

  • Enums with abstract methods (abstract enums)

  • Arrays with abstract component types containing concrete instances

  • Does this PR introduce any public API change?

  • Does this PR introduce any binary protocol compatibility change?

Benchmark

N/A - Bug fix only

@chaokunyang chaokunyang force-pushed the fix_graalvm_error_2695 branch from 7f7d41d to 3f9229e Compare December 29, 2025 06:32
@chaokunyang chaokunyang changed the title fix(java): fix graalvm for abstrct array/enum fix(java): fix abstract enum and abstract array serialization for GraalVM Dec 29, 2025
@chaokunyang chaokunyang merged commit 1027695 into apache:main Dec 29, 2025
52 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.

[Java] Abstract class corner cases failing: arrays and enums

2 participants