Skip to content

Fix #908: Resolve nested classes named by schema in AvroTypeIdResolver, not by probing in AvroSchemaHelper - #909

Closed
cowtowncoder wants to merge 1 commit into
2.xfrom
tatu-claude/2.x/908-avro-nested-class-lookup
Closed

cowtowncoder wants to merge 1 commit into
2.xfrom
tatu-claude/2.x/908-avro-nested-class-lookup

Conversation

@cowtowncoder

Copy link
Copy Markdown
Member

Fixes #908.

Problem

AvroSchemaHelper.getFullName(Schema) probed for nested classes (Class.forName() per dot of the schema namespace) to decide between pkg.Outer.Inner and pkg.Outer$Inner. It did so with the Avro module's own ClassLoader, while databind loads the resulting type id via TypeFactory.findClass() (context ClassLoader first), so the two could disagree; results went into a JVM-wide static cache; and classes named by a possibly untrusted schema were loaded when the schema was processed.

Change

  • AvroSchemaHelper.getFullName() no longer probes: returns the plain dotted name (or namespace$Name for old-style $ namespaces). The static resolver, its cache and the dot / length limits added in Do not initialize class named by Avro schema when resolving its full name #906 are removed from here.
  • Write side: AvroWriteContext.resolveUnionIndex() / resolveUnionType() use new AvroSchemaHelper.typeIdMatches(Class, Schema), which compares class name against schema name (accepting $ in class name where namespace has .). No class loading, no cache.
  • Read side: AvroTypeIdResolver resolves the dotted id into the actual nested class: tries id as given, then replaces dots with $ from the right, via DatabindContext.resolveAndValidateSubType(); so same ClassLoader lookup as databind, no class initialization, and subtype validation before loading. Results (including "no class found") are cached per resolver instance (100 entries), i.e. per mapper configuration. The 32-dot / 1024-char probing limits now live here.
  • Generic type ids built by AvroReaderFactory (java.util.EnumSet<pkg.Outer.MyEnum>) get names inside <...> resolved too.

Compatibility

  • JsonParser.getTypeId() now exposes pkg.Outer.Inner where it used to expose pkg.Outer$Inner for nested classes named by RECORD / ENUM / FIXED schemas.
  • Public AvroSchemaHelper.getFullName(Schema) / getTypeId(Schema) return the dotted form as well.

Tests

  • SchemaNameClassInitTest renamed to SchemaFullNameTest, rewritten for non-probing behavior; adds match / mismatch cases for typeIdMatches().
  • New NestedClassTypeId908Test: nested and doubly nested classes, $ namespaces, Map fallback for unknown names, probing limit boundaries.
  • Not covered: an actual multi-ClassLoader setup (Jackson in parent loader, POJOs in child); fix relies on databind's lookup for that.

🤖 Generated with Claude Code

…dResolver`, not by probing in `AvroSchemaHelper`

- `AvroSchemaHelper.getFullName()` no longer probes for (and loads) nested
  classes; returns plain dotted name. Static name cache removed.
- Union resolution on write matches class name against schema name with
  new `AvroSchemaHelper.typeIdMatches()`, without class loading.
- `AvroTypeIdResolver` resolves dotted type ids into nested class names
  using databind's class lookup (context ClassLoader first, no
  initialization, subtype validation), with per-resolver cache.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@cowtowncoder cowtowncoder changed the title Fix #908: (avro) resolve nested classes named by schema in AvroTypeIdResolver, not by probing in AvroSchemaHelper Fix #908: Resolve nested classes named by schema in AvroTypeIdResolver, not by probing in AvroSchemaHelper Nov 18, 2026
@cowtowncoder

Copy link
Copy Markdown
Member Author

Not feasible, closing.

@cowtowncoder
cowtowncoder deleted the tatu-claude/2.x/908-avro-nested-class-lookup branch November 18, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AvroSchemaHelper.getFullName() probes for nested classes with different ClassLoader than databind uses to load them

1 participant