Skip to content

Resolve forwarded type arguments across POJO hierarchy edges#2014

Draft
vbabanin wants to merge 9 commits into
mongodb:mainfrom
vbabanin:JAVA-6065
Draft

Resolve forwarded type arguments across POJO hierarchy edges#2014
vbabanin wants to merge 9 commits into
mongodb:mainfrom
vbabanin:JAVA-6065

Conversation

@vbabanin

@vbabanin vbabanin commented Jul 13, 2026

Copy link
Copy Markdown
Member

Adds substitution-aware TypeData.newInstance and wires PojoBuilderHelper to use it at both superclass and interface edges.

JAVA-6065
JAVA-5110
JAVA-6138

Note: Not self-reviewed yet.

Adds substitution-aware TypeData.newInstance and wires PojoBuilderHelper
to use it at both superclass and interface edges. Closes JAVA-5110 and
JAVA-6138.

This comment was marked as outdated.

@rozza

rozza commented Jul 13, 2026

Copy link
Copy Markdown
Member

@vbabanin I shouldn't have pushed my changes here (reverted) I have created a PR for additions to this branch: vbabanin#2

Initial thoughts are this looks good and I prefer over #2015 as its much more robust.

rozza and others added 8 commits July 13, 2026 22:45
Holder/NonGeneric fields must be private (VisibilityModifier); they are
read via reflection so accessors are unnecessary. Also drop the unused
Holder.scalar field.

JAVA-6065
resolveTypeArgument previously fell through to Object for a WildcardType,
so a wildcard nested inside a forwarded supertype argument (e.g.
extends Base<List<? extends Number>>) lost its bound. Resolve it to its
upper bound, mirroring getNestedTypeData, so a type variable inside the
bound is still substituted against the current context.

Adds a TypeData unit test for the bound resolution and a discriminated
POJO round-trip (ForwardingWildcardModel) that fails without the fix.

JAVA-6065
The two newInstance overloads duplicated near-identical type-argument
walking. resolveTypeArgument is a strict superset of getNestedTypeData
(with an empty context, type variables erase to Object exactly as
before), and it also fixes a latent ClassCastException when a wildcard's
upper bound is itself parameterized (e.g. ? extends List<String>).
Delegate the two-arg newInstance to it and remove getNestedTypeData.

JAVA-6065
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.

3 participants