-
Notifications
You must be signed in to change notification settings - Fork 109
Labels
Description
Predicates is not correctly handed by PreferJavaUtilPredicate recipe
- This issue follows the issue
Sets.newHashSet(Iterables.filter...is not correctly handed by NoGuavaSetsNewHashSet recipe #881. ThePredicateclass from Guava is converted injava.util.Predicateeven when it is used in aPredicates.andmethod that is not converted. As a result, the following error appears after migration:The method and(Predicate<? super T>, Predicate<? super T>) in the type Predicates is not applicable for the arguments (new Predicate<Object>(){}, new Predicate<Object>(){}).
I reproduced the issue with the simple class below.
The problem/solution would be the same for methods or, equalTo and not.
What version of OpenRewrite are you using?
I am using
- OpenRewrite v6.21.1
- Maven v3.9.5
- org.openrewrite.recipe:rewrite-migrate-java v3.19.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.NoGuavaSetsNewHashSet -Drewrite.exportDatatables=true -f packaging/org.eclipse.sirius.parent/pom.xmlWhat is the smallest, simplest way to reproduce the problem?
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
class Test {
public static void test() {
Predicate<Object> result = Predicates.and(new Predicate<Object>() {
@Override
public boolean apply(Object input) {
return false;
}
}, new Predicate<Object>() {
@Override
public boolean apply(Object input) {
return false;
}
});
}
}What did you expect to see?
The method Predicates.and can be replaced by java.util.function.Predicate.and(Predicate<? super T>).
import java.util.function.Predicate;
class Test {
public static void test() {
Predicate<Object> result = new Predicate<Object>() {
@Override
public boolean test(Object input) {
return false;
}
}.and(new Predicate<Object>() {
@Override
public boolean test(Object input) {
return false;
}
});
}
}What did you see instead?
import java.util.function.Predicate;
import com.google.common.base.Predicates;
class Test {
public static void test() {
Predicate<Object> result = Predicates.and(new Predicate<Object>() {
@Override
public boolean test(Object input) {
return false;
}
}, new Predicate<Object>() {
@Override
public boolean test(Object input) {
return false;
}
});
}
}Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done