Repository navigation
Probe for nested classes named by Avro schema using context ClassLoader first, at read time (fix #908) - #910
Open
cowtowncoder wants to merge 8 commits into
Open
cowtowncoder wants to merge 8 commits into
cowtowncoder wants to merge 8 commits into
Conversation
…okup (#908) `AvroSchemaHelper.getFullName()` probed for nested classes using the ClassLoader of the Avro module, which may not see application classes that databind loads via context ClassLoader; results were also retained in a JVM-wide cache. - `AvroSchemaHelper.getFullName()` no longer loads classes: returns dotted name from schema - `AvroWriteContext` matches union branches by name only - `AvroTypeIdResolver` probes for nested classes via `DatabindContext.resolveAndValidateSubType()`, with per-resolver cache; limits on dots/length (#906) moved there Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- Always resolve via `ClassNameIdResolver` after probing, and skip probing if `FAIL_ON_SUBTYPE_CLASS_NOT_REGISTERED` enabled - Add `AvroNestedClassTypeIdHandler` (registered by `AvroModule`) so that standard type id resolvers can resolve dotted ids of nested classes - Only retain successful lookups (as resolved names) in resolver cache - Handle names with mix of `$` and `.` separators, on read and write - Move probing limit tests to class that needs no compiler; test limits end-to-end by counting class loading attempts Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Instead of exposing dotted names as type ids and having `AvroTypeIdResolver` (plus a problem handler for standard resolvers) resolve them, translate names where type id is produced, so that all consumers get actual class names as before. - Add `AvroTypeIdClassNames`: probes using context ClassLoader first, then module's, without initializing classes; retains only names of classes found - `AvroParser` remembers outcome per type id for duration of parsing - Remove `AvroNestedClassTypeIdHandler`; revert `AvroTypeIdResolver` and `AvroModule` to what 2.x has Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- `AvroTypeIdClassNames.resolve()` always returns usable id; split handling of generic ids from class name probing - Single-expression two-loader lookup - Write side: compare names with separators unified (one helper) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
#908) - `AvroSchema.resolveTypeId()` retains type ids for which class was found (successful lookups only); shared by parsers using the schema - Remove per-parser map and JVM-wide cache; `AvroTypeIdClassNames` is now stateless - Assign `AvroParser._rootSchema` in `setSchema()` (was never assigned, so `getSchema()` always returned null) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Type id access may now require probing for nested classes, so only get it once in `deserializeWithType()` and `mapObject()`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Probing for nested classes was repeated for every value for which no class exists (common when binding as "untyped"). - `AvroSchema.resolveTypeId()` remembers type ids for which no class was found, for the ClassLoader most recently used (weakly referenced): lookup with another ClassLoader is done from scratch - Add `AvroTypeIdClassNames.lookupClassLoader()` Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- `AvroSchema`: retain outcomes of type id lookups (class found or not) separately for each ClassLoader (weakly referenced), so that neither leaks to usage with another ClassLoader, nor is lost when alternating - Retain type ids that are not probed for, too - `AvroTypeDeserializer`: only get type id once - Document change to `AvroSchemaHelper.getTypeId(Schema)`, and that `AvroParser.getSchema()` now returns schema Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
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 #908.
Problem
AvroSchemaHelper.getFullName(Schema)probed for nested classes with the ClassLoader that loaded the Avro module, while databind loads the class viaTypeFactory.findClass()(context ClassLoader first). When Jackson jars are in a parent loader and POJOs in a child / context loader, the probe finds nothing, the dotted fallback name is used (and cached JVM-wide), and polymorphic values come back asMaps.Changes
AvroSchemaHelper.getFullName()no longer loads classes at all: it returns the schema's dotted name.FullNameResolverand its static cache are removed, so nothing is probed at schema / reader construction.AvroParser.getTypeId()translates the name into the actual class name (pkg.Outer.Innertopkg.Outer$Inner) via new package-private helperAvroTypeIdClassNames:AvroSchema(new package-privateresolveTypeId()), shared by all parsers using the schema and bounded by number of types in it; only successful lookups are retained (names only, no class references), since failure may depend on context ClassLoaderAvroReaderFactoryforEnumSet/EnumMapare handled (first type parameter probed)AvroWriteContext.resolveUnionIndex()/resolveUnionType()match union branches by name only (exact, or with$/.separators unified): no class loading on write.AvroParser.setSchema()now assigns_rootSchema(it was never assigned), needed to reach the schema's cache.AvroTypeIdResolverandAvroModuleare unchanged.Compatibility
AvroParser.getTypeId()are as before ($for nested classes), for all consumers.AvroSchemaHelper.getFullName(Schema)/getTypeId(Schema)now returnpkg.Outer.Innerinstead ofpkg.Outer$Innerfor nested classes named by RECORD / ENUM / FIXED schemas.AvroParser.getSchema()now returns the schema in use (always returnednullbefore).getTypeId()call (one failed lookup per dot, up to the limits): failures are not cached.TypeFactory.withClassLoader(...)is not consulted.Tests
NestedClassTypeId908Test: compiles classes at test time into a ClassLoader the module cannot see; round-trips with and without context ClassLoader, with two loaders, and failure-then-success on one mapper and schema. Skipped if no Java compiler is available.NestedClassTypeIdResolution908Test: streaminggetTypeId()(no class initialization; unknown name), standard@JsonTypeInfo(use = Id.CLASS)resolver,FAIL_ON_SUBTYPE_CLASS_NOT_REGISTERED, mixed and legacy$names.NestedClassProbeLimits908Test: limits, including end-to-end count of class loading attempts.SchemaNameClassInitTest(Do not initialize class named by Avro schema when resolving its full name #906) updated for dotted names.Merge-forward note
NestedClassTypeId908Testusesjavax.tools: when merging to 3.x line,avro/src/test/java/module-info.javaneedsrequires java.compiler;.🤖 Generated with Claude Code