openrewrite / rewrite-migrate-java

OpenRewrite recipes for migrating to newer versions of Java.
Apache License 2.0
92 stars 65 forks source link

`PreferJavaUtilFunction` should not convert when used specifically as Guava type #436

Open timo-abele opened 3 months ago

timo-abele commented 3 months ago

How are you running OpenRewrite?

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

                <plugin>
                    <groupId>org.openrewrite.maven</groupId>
                    <artifactId>rewrite-maven-plugin</artifactId>
                    <version>5.23.1</version>
                    <configuration>
                        <activeRecipes>
                            <recipe>org.openrewrite.java.migrate.guava.NoGuavaJava11</recipe>
                        </activeRecipes>
                        <failOnDryRunResults>true</failOnDryRunResults>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.openrewrite.recipe</groupId>
                            <artifactId>rewrite-migrate-java</artifactId>
                            <version>2.10.0</version>
                        </dependency>
                    </dependencies>
                </plugin>

What is the Problem?

Example: in Collections2.transform(someList, com.google.common.base.Function) only the function is converted to a jdk equivalent. This breaks the build because transform only accepts a guava Function.

Are you interested in contributing a fix to OpenRewrite?

No, sorry

timtebeek commented 2 months ago

Thanks for calling that out! We could indeed look to see if there's any surrounding method invocation that requires a Guava type, or even look how the type is used through https://github.com/openrewrite/rewrite-analysis/ to limit when we make changes.