diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 5f2f44045ef..a98ab8d2e9e 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -676,6 +676,19 @@ Flux after(Flux flux) { } } + /** Drop redundant {@link Class#isInstance} in {@link Mono#onErrorResume(Function)}. */ + static final class MonoOnErrorResume { + @BeforeTemplate + Mono before(Mono mono, Class clazz, Mono other) { + return mono.onErrorResume(clazz::isInstance, e -> other); + } + + @AfterTemplate + Mono after(Mono mono, Class clazz, Mono other) { + return mono.onErrorResume(clazz, e -> other); + } + } + /** Prefer {@link reactor.util.context.Context#empty()}} over more verbose alternatives. */ // XXX: Consider introducing an `IsEmpty` matcher that identifies a wide range of guaranteed-empty // `Collection` and `Map` expressions. diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 8c33d36b805..0e7519921eb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -218,6 +218,11 @@ ImmutableSet> testFluxOnErrorComplete() { Flux.just(2).onErrorResume(e -> Flux.empty())); } + Mono testMonoOnErrorResume() { + return Mono.just(1) + .onErrorResume(IllegalArgumentException.class::isInstance, e -> Mono.just(2)); + } + ImmutableSet testContextEmpty() { return ImmutableSet.of(Context.of(new HashMap<>()), Context.of(ImmutableMap.of())); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index b943f50ea4d..795db5fcb45 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -218,6 +218,10 @@ ImmutableSet> testFluxOnErrorComplete() { return ImmutableSet.of(Flux.just(1).onErrorComplete(), Flux.just(2).onErrorComplete()); } + Mono testMonoOnErrorResume() { + return Mono.just(1).onErrorResume(IllegalArgumentException.class, e -> Mono.just(2)); + } + ImmutableSet testContextEmpty() { return ImmutableSet.of(Context.empty(), Context.empty()); }