fix(core): keep TypeDef root kind consistent for factory custom serializers - #4022
Open
Pigsy-Monk wants to merge 5 commits into
Open
fix(core): keep TypeDef root kind consistent for factory custom serializers#4022Pigsy-Monk wants to merge 5 commits into
Pigsy-Monk wants to merge 5 commits into
Conversation
…lizers ClassResolver.getTypeDefRootTypeId treated unregistered classes handled by a configured SerializerFactory as struct-owned (NAMED_COMPATIBLE_STRUCT=30) when no TypeInfo existed yet, while the writer encoded NAMED_EXT=32. Probe the SerializerFactory (cached, re-entrancy guarded, conservative on error): when it would supply a custom serializer, normalize the root kind to NAMED_EXT so reader and writer agree. Regression test: two identical instances sharing meta contexts, neither pre-registering the factory-serialized class, round-trip a struct that nests the non-collection subclass; the pre-registration variant is also verified.
…omputeIfAbsent Replace three HashSet caches + manual re-entrancy guard with a single ConcurrentHashMap<Class<?>, Boolean> and computeIfAbsent. Thread-safe, simpler, same semantics. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #4021.
A fresh reader can infer a struct kind for a plain class whose configured
SerializerFactoryactually supplies an extension serializer. Native TypeDefvalidation then rejects bytes written by an identically configured instance.
Resolve empty extension roots through the existing
ClassResolver.getTypeInfopath before validating their kind. The resolver retains the actual serializer
and type ID, including when metadata previously created a provisional TypeInfo.
This requires no additional cache or factory probe.
Keep each serializer's root definition on
TypeInfo, independently of the classfield schemas used by metadata probes and ObjectStream layers. Local-header
matching checks an available root definition before the field schema, without
creating a serializer just to probe for a match. This preserves cold registered
struct and ObjectStream layer matches and prevents a cached field schema from
replacing an extension's empty root definition.
Tests
Expanded
SerializerFactoryTestcovers the original polymorphic custom serializer,metadata-first and typed-root reads, read-then-write reuse, enum and recursive
struct factories, factory failure recovery, registration, and both codegen modes.
It also verifies that each custom serializer is created once per resolver.
fory-coresuite on JDK 21: 2,252 passed, 58 skipped, no failures or errors.that exact-local schemas do not consume the remote-schema allowance, plus
existing ObjectStream layer, registration, and schema-consistent meta-share cases.