Skip to content

Skip explicit type arguments containing wildcards in UseVarForGenericMethodInvocations#1102

Merged
timtebeek merged 1 commit into
mainfrom
tim/fix-wildcard-compile
May 16, 2026
Merged

Skip explicit type arguments containing wildcards in UseVarForGenericMethodInvocations#1102
timtebeek merged 1 commit into
mainfrom
tim/fix-wildcard-compile

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • UseVarForGenericMethodInvocations was emitting invalid Java when the variable type contained a wildcard, e.g. Class<?> x = cl.loadClass(...) became var x = cl.<?>loadClass(...). Wildcards are not valid explicit type arguments on a method invocation.
  • Now skip adding explicit type parameters to the method invocation when any of the LHS type parameters is a J.Wildcard; the var rewrite still proceeds.
  • Added a regression test covering Class<?> recipeClass = cl.loadClass(...).

Test plan

  • ./gradlew test --tests UseVarForGenericMethodInvocationsTest

…cMethodInvocations`

Wildcards (`?`) are not valid as explicit type arguments on a method
invocation, so e.g. `Class<?> x = cl.loadClass(...)` was being rewritten
to invalid `var x = cl.<?>loadClass(...)`.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite May 16, 2026
@timtebeek timtebeek merged commit f7a3287 into main May 16, 2026
1 check passed
@timtebeek timtebeek deleted the tim/fix-wildcard-compile branch May 16, 2026 10:57
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant