-
Notifications
You must be signed in to change notification settings - Fork 110
Closed
Labels
Description
- This issue is similar to the issue Sets.filter is not migrated, which creates a conflict with the PreferJavaUtilPredicate recipe #897. The
Predicateclass from Guava is converted injava.util.Predicateeven when it is used in aCollections2.filtermethod that is not converted. As a result, the following error appears after migration:The method filter(Collection<E>, Predicate<? super E>) in the type Collections2 is not applicable for the arguments (Collection<Object>, Predicate<Object>).
What version of OpenRewrite are you using?
I am using
- Rewrite Maven Plugin v6.22.1
- Maven v3.9.5
- org.openrewrite.recipe:rewrite-migrate-java v3.20.0
How are you running OpenRewrite?
I used the Maven command line to launch the recipe on the Sirius Desktop repository :
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.migrate.guava.NoGuava -Drewrite.exportDatatables=true -f packaging/org.eclipse.sirius.parent/pom.xmlWhat is the smallest, simplest way to reproduce the problem?
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
class Test {
public static Collection<Object> test() {
Collection<Object> collection = new ArrayList<>();
Predicate<Object> isNotNull = Objects::nonNull;
return Collections2.filter(collection, isNotNull);
}
}What did you expect to see?
The method Collections2.filter can be replaced by Collection.stream().filter(Predicate<? super T>).toList().
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import java.util.function.Predicate;
class Test {
public static Collection<Object> test() {
Collection<Object> collection = new ArrayList<>();
Predicate<Object> isNotNull = Objects::nonNull;
return collection.stream().filter(isNotNull).toList();
}
}What did you see instead?
import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import com.google.common.collect.Collections2;
class Test {
public static Collection<Object> test() {
Collection<Object> collection = new ArrayList<>();
Predicate<Object> isNotNull = Objects::nonNull;
return Collections2.filter(collection, isNotNull);
}
}Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done