Skip to content

fix: terminate wildcard erasure lookup#6803

Open
martinfrancois wants to merge 2 commits into
INRIA:masterfrom
martinfrancois:agent/issue-6802-type-parameter-erasure
Open

fix: terminate wildcard erasure lookup#6803
martinfrancois wants to merge 2 commits into
INRIA:masterfrom
martinfrancois:agent/issue-6802-type-parameter-erasure

Conversation

@martinfrancois

@martinfrancois martinfrancois commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Prevent recursive type erasure when Spoon resolves a bounded wildcard in no-classpath mode.

Fixes #6802.

Problem

Type erasure is the simpler type Spoon uses when it compares generic method or constructor signatures. For a parameter such as ? extends E, Spoon tried to compute that type by finding a declaration named ?. Resolving the bound E then requested the containing method declaration. Matching that method erased the same wildcard parameter again, so the cycle repeated until a StackOverflowError occurred.

Change

  • Erase an upper-bounded wildcard to the erasure of its bound.
  • Erase a lower-bounded wildcard to Object.
  • Guard executable matching against re-entering the same executable reference through nested or sibling type parameters.
  • Traverse paired return, parameter, declaring, wildcard, array, and generic-argument types with one ordered worklist, preserving the existing first-match order.
  • After exact method or constructor lookup succeeds, follow the reference's array, wildcard, declaring-type, and generic-argument path to the corresponding nested declaration.
  • Keep the surrounding lexical declaration for references created from a lexical type parameter, including after reparenting, cloning, and model serialization.
  • Identify parsed declaration owners by source location rather than mutable method or type names, and retain the owner marker when the model is cloned or serialized.
  • Resolve unnamed in-memory source files through Spoon's compilation-unit cache so the same declaration keeps one stable owner.
  • Preserve intentional not-found results in declaration lookup helpers while satisfying the repository's Qodana requirements.

Validation

  • Added a reduced no-classpath regression that produces a StackOverflowError before the fix and terminates after the fix.
  • mvn -q -Dtest=spoon.test.reference.TypeParameterErasureRecursionTest test passes all 24 focused tests, including positionless overloads, renamed parsed methods and types, direct-bound reparenting, cloning, serialization, and unnamed in-memory sources.
  • mvn -q -Dtest=spoon.test.generics.GenericsTest,spoon.test.reference.TypeReferenceTest test passes all 96 tests.
  • mvn -q verify passes with 16 skipped and no failures or errors.
  • As a compatibility replay, StoneDetector processes the historical Elasticsearch AttributeMap.java: AST 1/1, CFG 5/5, dominators 5/5, paths 5/5, and no reported errors. That full file also passes on the audited upstream base, so the reduced regression above is the discriminating evidence.
  • All 14 GitHub checks pass, including the main Qodana check and the Java 17, 21, and 25 test matrix.

@martinfrancois
martinfrancois force-pushed the agent/issue-6802-type-parameter-erasure branch from 1ad9e58 to 1191cca Compare July 17, 2026 17:17
@martinfrancois
martinfrancois marked this pull request as ready for review July 17, 2026 19:17
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.

[Bug]: Bounded wildcard erasure recursively overflows

1 participant