Skip to content

Commit

Permalink
PR comments - add proper compatibility with Mono.empty publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaLegeza committed Dec 12, 2023
1 parent 56e9e39 commit 1c96be3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import static com.google.errorprone.BugPattern.LinkType.CUSTOM;
import static com.google.errorprone.BugPattern.SeverityLevel.ERROR;
import static com.google.errorprone.BugPattern.StandardTags.LIKELY_ERROR;
import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE;
import static com.google.errorprone.matchers.Matchers.allOf;
import static com.google.errorprone.matchers.Matchers.anyOf;
import static com.google.errorprone.matchers.Matchers.argument;
import static com.google.errorprone.matchers.Matchers.hasArguments;
import static com.google.errorprone.matchers.Matchers.instanceMethod;
import static com.google.errorprone.matchers.Matchers.staticMethod;
import static com.google.errorprone.matchers.Matchers.toType;
Expand Down Expand Up @@ -73,11 +76,18 @@ public final class MonoZipOfMonoVoidUsage extends BugChecker
toType(MethodInvocationTree.class, hasGenericArgumentOfExactType(MONO_VOID_TYPE))),
allOf(
instanceMethod().onDescendantOf(MONO).named("zipWith"),
toType(MethodInvocationTree.class, staticMethod().onClass(MONO).named("empty"))),
toType(
MethodInvocationTree.class,
argument(0, staticMethod().onClass(MONO).named("empty")))),
onClassWithMethodName(MONO_VOID_TYPE, "zipWith"),
allOf(
staticMethod().onClass(MONO).named("zip"),
toType(MethodInvocationTree.class, hasGenericArgumentOfExactType(MONO_VOID_TYPE))));
toType(MethodInvocationTree.class, hasGenericArgumentOfExactType(MONO_VOID_TYPE))),
allOf(
staticMethod().onClass(MONO).named("zip"),
toType(
MethodInvocationTree.class,
hasArguments(AT_LEAST_ONE, staticMethod().onClass(MONO).named("empty")))));

/** Instantiates a new {@link MonoZipOfMonoVoidUsage} instance. */
public MonoZipOfMonoVoidUsage() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

final class MonoZipOfMonoVoidUsageTest {
/**
* Line 44 won't be reported as a bug. It's quite hard to catch this case as {@code Mono.empty()}
* yields {@code Mono<Object>}, so matcher will be too wide. Additionally, it's not expected to
* occur in the real production code.
*
* <p>Line 25 needed to simulate the unwanted intrinsic operations, which are not intended to be
* processed by the rule.
* Line 21 is needed to simulate the unwanted intrinsic operations, which are not intended to be
* processed by the rule but will be scanned anyway.
*/
@Test
void identification() {
Expand Down Expand Up @@ -41,6 +37,9 @@ void identification() {
" Mono.zip(d, c, b, a);",
" Mono.zip(d, c, b);",
" b.zipWith(b).zipWith(c).map(entry -> entry);",
" // BUG: Diagnostic contains: `Mono#zip` and `Mono#zipWith` should not be executed against",
" // `Mono#empty` or `Mono<Void>` parameter; please revisit the parameters used and make sure to",
" // supply correct publishers instead",
" Mono.zip(d, Mono.empty());",
" c.zipWith(b);",
" c.zipWith(d);",
Expand All @@ -61,6 +60,10 @@ void identification() {
" // `Mono#empty` or `Mono<Void>` parameter; please revisit the parameters used and make sure to",
" // supply correct publishers instead",
" a.zipWith(c, (first, second) -> second);",
" // BUG: Diagnostic contains: `Mono#zip` and `Mono#zipWith` should not be executed against",
" // `Mono#empty` or `Mono<Void>` parameter; please revisit the parameters used and make sure to",
" // supply correct publishers instead",
" c.zipWith(Mono.empty());",
" }",
"",
" private Mono<Integer> publisher() {",
Expand Down

0 comments on commit 1c96be3

Please sign in to comment.