Skip to content

UseVarForGenericMethodInvocations breaks explicitType argument for nested generic factorymMethod #868

@jagodevreede

Description

@jagodevreede

What version of OpenRewrite are you using?

I am using

  • Maven plugin v6.18.0
  • rewrite-migrate-java 3.18.0

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a multi module project.

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>6.18.0</version>
        <configuration>
          <exportDatatables>true</exportDatatables>
          <activeRecipes>
            <recipe>org.openrewrite.java.migrate.lang.var.UseVarForGenericMethodInvocations</recipe>
          </activeRecipes>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.openrewrite.recipe</groupId>
            <artifactId>rewrite-migrate-java</artifactId>
            <version>3.18.0</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</project>

What is the smallest, simplest way to reproduce the problem?

public class A<T> {
    void getX(final Root<T> root) {
        Path<T> x = root.get("x");
    }
}
interface Root<X>{
    <Y> Path<Y> get(String var1);
}
interface Path<X> { }

What did you expect to see?

public class A<T> {
    void getX(final Root<T> root) {
        var x = root.<T>get("x");
    }
}
interface Root<X>{
    <Y> Path<Y> get(String var1);
}
interface Path<X> { }

or not converted to var

public class A<T> {
    void getX(final Root<T> root) {
        Path<T> x = root.get("x");
    }
}
interface Root<X>{
    <Y> Path<Y> get(String var1);
}
interface Path<X> { }

What did you see instead?

public class A<T> {
    void getX(final Root<T> root) {
        var x = root.get("x");
    }
}
interface Root<X>{
    <Y> Path<Y> get(String var1);
}
interface Path<X> { }

What is the full stack trace of any errors you encountered?

stacktrace output here

Are you interested in contributing a fix to OpenRewrite?

I will create a draft PR that contains a test, and a regression test that possibly will break if an attempt to fix is being made.
I've also have a patch that is 90% GTP5 that will work, but is has rewritten quite a bit of code, it does work on a large codebase. (That is also where the regression test comes from) Are you interested in this AI solution?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions