Skip to content

Methods with generic arguments are not matched #5047

Open
@triceo

Description

Discussed in #5038

In my Java code, I have an interface X<A> with the following method:

default <Y_ extends Y<Y_>> @NonNull Z<A, Y_> doSomething(@NonNull Y_ y);

I am trying to write a pattern that would match this method. I have this, which should work, but doesn't:

fully.qualified.X doSomething(fully.qualified.Y)

The pattern suddenly starts to match when I use the specific implementation of Y (let's call it YImpl) which I actually use in the test for the recipe:

fully.qualified.X doSomething(fully.qualified.YImpl)

To provide a more explicit example:

  • Consider a method like default <Number_ extends Number> @NonNull Set<Number_> doSomething(@NonNull Number_ number);. Let's assume this method is declared on an interface com.github.MyInterface.
  • Further consider we're migrating source code like this: myInterfaceImpl.doSomething(BigDecimal.ONE);
  • This pattern will not match the code: com.github.MyInterface doSomething(java.lang.Number)
  • This pattern will match: com.github.MyInterface doSomething(java.math.BigDecimal)

The expected result is that the first pattern will match too.

I'm on rewrite-recipe-bom 3.1.0 and OpenJDK 21 (Temurin).
It is possible that the @NonNull annotations have no effect and can be removed; I have not tried that.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

Type

Projects

  • Status

    Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions