Skip to content

Fix crash on a lambda or method reference cast to an intersection with a wildcard bound - #8660

Open
mernst wants to merge 5 commits into
typetools:masterfrom
mernst:intersection-cast-wildcard-crash
Open

mernst wants to merge 5 commits into
typetools:masterfrom
mernst:intersection-cast-wildcard-crash

Conversation

@mernst

@mernst mernst commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Land before #8657.

The Checker Framework crashed with an IndexOutOfBoundsException in AnnotatedTypeFactory.makeGroundTargetType on a lambda or method reference whose target is an intersection type with a wildcard-parameterized bound, such as:

Object o = (Serializable & Supplier<? extends String>) () -> "";

javac's type for such a lambda is the intersection type, not the functional interface, so makeGroundTargetType read type arguments from a type that has none. Now getFnInterfaceFromTree passes the bound of javac's intersection type that instantiates the functional interface.

The new test framework/tests/all-systems/IntersectionCastWildcard.java crashes without the fix.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 85cec31 and 4287b0a.

Files selected for processing: 2

  • framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java
  • framework/tests/all-systems/IntersectionCastWildcard.java

No actionable comments were generated in the recent review.

Walkthrough

getFnInterfaceFromTree now uses groundTargetJavaType to obtain a ground target type before calling makeGroundTargetType. For intersection types, the helper selects the bound whose erasure matches the functional interface’s erasure, or throws BugInCF if no bound matches. A new test adds lambda and method-reference examples with wildcard and raw functional-interface intersection bounds.

Possibly related PRs

Suggested reviewers: smillst

Change: Bug fix

Merge Risk: Minimal · previous review 85cec

This change fixes a checker crash when a lambda or method reference is cast to an intersection type with a wildcard-parameterized functional interface. No merge-blocking risk was identified.

Pre-merge checks: Passed 2

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8348c92 and 85cec31.

Files selected for processing: 2

  • framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java
  • framework/tests/all-systems/IntersectionCastWildcard.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

…ildcard bounds

Define "ground target type" in the Javadoc of groundTargetJavaType and
document when it throws.  Detect an intersection by its kind, and explain
why a cast to DeclaredType is not enough.  Test raw functional bounds,
unbounded wildcards (including one whose type parameter has a bound),
and parenthesized lambdas and method references.
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.

2 participants