diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonEmptyMono.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonEmptyMono.java index a0b00e9b59b..a6ae88cd542 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonEmptyMono.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonEmptyMono.java @@ -56,12 +56,10 @@ public final class NonEmptyMono extends BugChecker implements MethodInvocationTr "collectMultimap", "collectSortedList", "count", - "defaultIfEmpty", "elementAt", "hasElement", "hasElements", "last", - "reduce", "reduceWith", "single"), instanceMethod() diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonEmptyMonoTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonEmptyMonoTest.java index 86c06e466d3..820ed28a2ff 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonEmptyMonoTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonEmptyMonoTest.java @@ -28,91 +28,37 @@ void identification() { "class A {", " void m() {", " // BUG: Diagnostic contains:", - " Flux.just().collect(toImmutableList()).single();", + " Flux.just().all(x -> true).defaultIfEmpty(true);", " // BUG: Diagnostic contains:", - " Flux.just().collect(toImmutableList()).defaultIfEmpty(ImmutableList.of());", - " // BUG: Diagnostic contains:", - " Flux.just().collect(toImmutableList()).switchIfEmpty(Mono.just(ImmutableList.of()));", + " Flux.just().any(x -> true).single();", "", " // BUG: Diagnostic contains:", - " Flux.just().collect(ImmutableList::of, (list, item) -> {}).single();", - " // BUG: Diagnostic contains:", - " Flux.just().collect(ImmutableList::of, (list, item) -> {}).defaultIfEmpty(ImmutableList.of());", - " Flux.just()", - " .collect(ImmutableList::of, (list, item) -> {})", - " // BUG: Diagnostic contains:", - " .switchIfEmpty(Mono.just(ImmutableList.of()));", - "", - " // BUG: Diagnostic contains:", - " Flux.just().collectList().single();", + " Flux.just().collect(toImmutableList()).switchIfEmpty(Mono.just(ImmutableList.of()));", " // BUG: Diagnostic contains:", " Flux.just().collectList().defaultIfEmpty(ImmutableList.of());", " // BUG: Diagnostic contains:", - " Flux.just().collectList().switchIfEmpty(Mono.just(ImmutableList.of()));", - "", - " // BUG: Diagnostic contains:", - " Flux.just().collectSortedList().single();", - " // BUG: Diagnostic contains:", - " Flux.just().collectSortedList().defaultIfEmpty(ImmutableList.of());", - " // BUG: Diagnostic contains:", - " Flux.just().collectSortedList().switchIfEmpty(Mono.just(ImmutableList.of()));", - "", - " // BUG: Diagnostic contains:", - " Flux.just().collectSortedList((o1, o2) -> 1).single();", - " // BUG: Diagnostic contains:", - " Flux.just().collectSortedList((o1, o2) -> 1).defaultIfEmpty(ImmutableList.of());", - " // BUG: Diagnostic contains:", - " Flux.just().collectSortedList((o1, o2) -> 1).switchIfEmpty(Mono.just(ImmutableList.of()));", - "", - " // BUG: Diagnostic contains:", " Flux.just().collectMap(identity()).single();", - " // BUG: Diagnostic contains:", - " Flux.just().collectMap(identity()).defaultIfEmpty(ImmutableMap.of());", - " // BUG: Diagnostic contains:", - " Flux.just().collectMap(identity()).switchIfEmpty(Mono.just(ImmutableMap.of()));", - "", - " // BUG: Diagnostic contains:", - " Flux.just().collectMap(identity(), identity()).single();", - " // BUG: Diagnostic contains:", - " Flux.just().collectMap(identity(), identity()).defaultIfEmpty(ImmutableMap.of());", - " // BUG: Diagnostic contains:", - " Flux.just().collectMap(identity(), identity()).switchIfEmpty(Mono.just(ImmutableMap.of()));", - "", - " // BUG: Diagnostic contains:", - " Flux.just().collectMap(identity(), identity(), ImmutableMap::of).single();", - " Flux.just()", - " .collectMap(identity(), identity(), ImmutableMap::of)", - " // BUG: Diagnostic contains:", - " .defaultIfEmpty(ImmutableMap.of());", " Flux.just()", - " .collectMap(identity(), identity(), ImmutableMap::of)", + " .collectMultimap(identity(), identity(), ImmutableMap::of)", " // BUG: Diagnostic contains:", " .switchIfEmpty(Mono.just(ImmutableMap.of()));", + " // BUG: Diagnostic contains:", + " Flux.just().collectSortedList((o1, o2) -> 1).defaultIfEmpty(ImmutableList.of());", "", " // BUG: Diagnostic contains:", - " Flux.just().collectMultimap(identity()).single();", + " Flux.just().count().single();", " // BUG: Diagnostic contains:", - " Flux.just().collectMultimap(identity()).defaultIfEmpty(ImmutableMap.of());", + " Flux.just().elementAt(0).defaultIfEmpty(1);", " // BUG: Diagnostic contains:", - " Flux.just().collectMultimap(identity()).switchIfEmpty(Mono.just(ImmutableMap.of()));", - "", + " Flux.just().hasElement(0).single();", " // BUG: Diagnostic contains:", - " Flux.just().collectMultimap(identity(), identity()).single();", + " Flux.just().hasElements().switchIfEmpty(Mono.just(true));", " // BUG: Diagnostic contains:", - " Flux.just().collectMultimap(identity(), identity()).defaultIfEmpty(ImmutableMap.of());", + " Flux.just().last().defaultIfEmpty(1);", " // BUG: Diagnostic contains:", - " Flux.just().collectMultimap(identity(), identity()).switchIfEmpty(Mono.just(ImmutableMap.of()));", - "", + " Flux.just().reduceWith(() -> 1, (x, y) -> x).single();", " // BUG: Diagnostic contains:", - " Flux.just().collectMultimap(identity(), identity(), ImmutableMap::of).single();", - " Flux.just()", - " .collectMultimap(identity(), identity(), ImmutableMap::of)", - " // BUG: Diagnostic contains:", - " .defaultIfEmpty(ImmutableMap.of());", - " Flux.just()", - " .collectMultimap(identity(), identity(), ImmutableMap::of)", - " // BUG: Diagnostic contains:", - " .switchIfEmpty(Mono.just(ImmutableMap.of()));", + " Flux.just().single().switchIfEmpty(Mono.just(1));", " }", "}") .doTest();