diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterParameterOrder.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterParameterOrder.java index 762c6e7e0f5..16e2578740b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterParameterOrder.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterParameterOrder.java @@ -60,6 +60,9 @@ public final class RefasterParameterOrder extends BugChecker implements ClassTre private static final Matcher BEFORE_OR_AFTER_TEMPLATE_METHOD = anyOf(BEFORE_TEMPLATE_METHOD, hasAnnotation(AfterTemplate.class)); + /** Instantiates a new {@link RefasterParameterOrder} instance. */ + public RefasterParameterOrder() {} + @Override public Description matchClass(ClassTree tree, VisitorState state) { ImmutableList methods = getMethodsByPriority(tree, state); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java index 0b30db18b56..e47918d4bc5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java @@ -157,23 +157,13 @@ Predicate after() { } /** Avoid contrived ways of handling {@code null} values during equality testing. */ - static final class EqualsLhsNullable { - @BeforeTemplate - boolean before(S value2, T value1) { - return Optional.ofNullable(value1).equals(Optional.of(value2)); - } - - @AfterTemplate - boolean after(S value2, T value1) { - return value2.equals(value1); - } - } - - /** Avoid contrived ways of handling {@code null} values during equality testing. */ - static final class EqualsRhsNullable { + static final class Equals { @BeforeTemplate boolean before(T value1, S value2) { - return Optional.of(value1).equals(Optional.ofNullable(value2)); + return Refaster.anyOf( + Optional.of(value1).equals(Optional.of(value2)), + Optional.of(value1).equals(Optional.ofNullable(value2)), + Optional.ofNullable(value2).equals(Optional.of(value1))); } @AfterTemplate @@ -183,7 +173,7 @@ boolean after(T value1, S value2) { } /** Avoid contrived ways of handling {@code null} values during equality testing. */ - static final class EqualsLhsAndRhsNullable { + static final class ObjectsEquals { @BeforeTemplate boolean before(T value1, S value2) { return Optional.ofNullable(value1).equals(Optional.ofNullable(value2)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java index 93b97640790..016580a6475 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java @@ -69,15 +69,14 @@ Predicate testPredicateLambda() { return not(v -> v.isEmpty()); } - boolean testEqualsLhsNullable() { - return Optional.ofNullable("foo").equals(Optional.of("bar")); - } - - boolean testEqualsRhsNullable() { - return Optional.of("foo").equals(Optional.ofNullable("bar")); + ImmutableSet testEquals() { + return ImmutableSet.of( + Optional.of("foo").equals(Optional.of("bar")), + Optional.of("baz").equals(Optional.ofNullable("qux")), + Optional.ofNullable("quux").equals(Optional.of("quuz"))); } - boolean testEqualsLhsAndRhsNullable() { + boolean testObjectsEquals() { return Optional.ofNullable("foo").equals(Optional.ofNullable("bar")); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java index c61eb767482..39bab876fab 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java @@ -69,15 +69,11 @@ Predicate testPredicateLambda() { return v -> !v.isEmpty(); } - boolean testEqualsLhsNullable() { - return "bar".equals("foo"); + ImmutableSet testEquals() { + return ImmutableSet.of("foo".equals("bar"), "baz".equals("qux"), "quuz".equals("quux")); } - boolean testEqualsRhsNullable() { - return "foo".equals("bar"); - } - - boolean testEqualsLhsAndRhsNullable() { + boolean testObjectsEquals() { return Objects.equals("foo", "bar"); } }