fix: partial descriptor behavior - #3215
Open
inemtsev wants to merge 2 commits into
Open
Conversation
Author
|
Hi @sandwwraith @fzhinkin, please take a look at this improvement. It fixes a crash path (that was commented for @JsonNames annotation in the past), but also allows me to clean up try/catch in #3189 Would be great to apply this fix first before cleaning up the above PR. |
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.
Fixes #1512
Problem
PluginGeneratedSerialDescriptorinstances created without a generated serializer throwArrayIndexOutOfBoundsExceptionfromhashCode(),equals()andtoString(). This happensfor serializers produced by the
@Serializer(forClass = ...)companion shortcut:For these, the plugin constructs the descriptor with
generatedSerializer = null, sochildSerializersis empty while elementsCount > 0 and all three identity methods walkgetElementDescriptor(i), which indexes into the empty array.
The bug is invisible on ordinary encode/decode (nothing calls
hashCode), but it breaks anyfeature that uses descriptors as cache keys in
DescriptorSchemaCache. This is exactly thecrash reported in #1512 (open since 2021). The stack trace there is this path verbatim:
DescriptorSchemaCache.get->PluginGeneratedSerialDescriptor.hashCode-> AIOOBE. Theoriginally reported trigger is
useAlternativeNames = true(the documented limitation:JsonCustomSerializersTestmust run withuseAlternativeNames = false), and a later reportin that thread hits the same crash via
coerceInputValues = true. Because the root cause isdescriptor identity itself, every schema-cache entry point is affected the same way: in #3189
it forced a try-catch around the schema-cache lookup, and any future descriptor-keyed cache
would inherit the same landmine.
Fix
Identity of such "incomplete" descriptors is now computed from data the descriptor itself
owns: serial name, type parameters, kind, and element names, instead of the child descriptors
it cannot provide:
equals/hashCode contract intact with two different hash formulas. The kind check also
prevents accidental equality with EnumDescriptor, which reuses the null-serializer
construction but overrides hashCode itself.
The new branch executes only inside the existing lazy _hashCode initializer and in equals,
so there is no hot-path cost (verified: TwitterFeedBenchmark decode/encode at parity with
master).
decodeTwitterencodeTwitter