diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java index a8eb97b452..1491b18eac 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java @@ -388,6 +388,7 @@ static final class OptionalIdentity { @BeforeTemplate Optional before(Optional optional, Comparator comparator) { return Refaster.anyOf( + optional.or(Refaster.anyOf(() -> Optional.empty(), Optional::empty)), optional.stream().findFirst(), optional.stream().findAny(), optional.stream().min(comparator), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java index c09719bea5..20eb7fe221 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java @@ -118,10 +118,12 @@ ImmutableSet> testOptionalOrOtherOptional() { ImmutableSet> testOptionalIdentity() { return ImmutableSet.of( - Optional.of("foo").stream().findFirst(), - Optional.of("bar").stream().findAny(), - Optional.of("baz").stream().min(String::compareTo), - Optional.of("qux").stream().max(String::compareTo)); + Optional.of("foo").or(() -> Optional.empty()), + Optional.of("bar").or(Optional::empty), + Optional.of("baz").stream().findFirst(), + Optional.of("qux").stream().findAny(), + Optional.of("quux").stream().min(String::compareTo), + Optional.of("quuz").stream().max(String::compareTo)); } ImmutableSet> testOptionalFilter() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java index 8881529247..cf589e9d94 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java @@ -115,7 +115,12 @@ ImmutableSet> testOptionalOrOtherOptional() { ImmutableSet> testOptionalIdentity() { return ImmutableSet.of( - Optional.of("foo"), Optional.of("bar"), Optional.of("baz"), Optional.of("qux")); + Optional.of("foo"), + Optional.of("bar"), + Optional.of("baz"), + Optional.of("qux"), + Optional.of("quux"), + Optional.of("quuz")); } ImmutableSet> testOptionalFilter() {