EmptyMonoZip

ERROR

LikelyError

View source code on GitHub

Summary

Don’t pass a Mono<Void> or Mono.empty() argument to Mono#{zip,With}

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("EmptyMonoZip") to the enclosing element.

Disable this pattern completely by adding -Xep:EmptyMonoZip:OFF as compiler argument. Learn more.

Samples

Replacement

Shows the difference in example code before and after the bug pattern is applied.

Identification

Shows code lines which will (not) be flagged by this bug pattern.
A //BUG: Diagnostic contains: comment is placed above any violating line.

import static reactor.core.publisher.Mono.zip;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

class A {
  void m() {
    Flux.just(1).zip(Mono.empty(), Flux.just(2));

    Mono<Void> voidMono = Mono.empty();
    Mono<Integer> integerMono = Mono.empty();

    zip(Mono.just(1), Mono.just(2));
    Mono.zip(Mono.just(1), Mono.just(2));
    Mono.zip(Mono.just(1), Mono.just(2), Mono.just(3));
    Mono.zip(integerMono, integerMono);

    // BUG: Diagnostic matches: ARGUMENT
    zip(Mono.empty(), Mono.empty());
    // BUG: Diagnostic matches: ARGUMENT
    Mono.zip(Mono.empty(), Mono.empty());
    // BUG: Diagnostic matches: ARGUMENT
    Mono.zip(voidMono, Mono.just(1));
    // BUG: Diagnostic matches: ARGUMENT
    Mono.zip(voidMono, voidMono);
    // BUG: Diagnostic matches: ARGUMENT
    Mono.zip(Mono.just(1).then(), Mono.just(2));
    // BUG: Diagnostic matches: ARGUMENT
    Mono.zip(Mono.just(1), Mono.just(2), voidMono);

    Mono.just(1).zipWith(Mono.just(2));
    Mono.just(1).zipWith(integerMono);
    Mono.just(1).zipWith(integerMono, (a, b) -> a + b);

    // BUG: Diagnostic matches: ARGUMENT
    Mono.just(1).zipWith(Mono.empty());
    // BUG: Diagnostic matches: ARGUMENT
    Mono.just(1).zipWith(voidMono);
    // BUG: Diagnostic matches: RECEIVER
    Mono.empty().zipWith(Mono.just(1));
    // BUG: Diagnostic matches: RECEIVER
    voidMono.zipWith(Mono.just(1));
  }

  abstract class MyMono extends Mono<Object> {
    void m() {
      zip(Mono.just(1), Mono.just(2));
      // BUG: Diagnostic matches: ARGUMENT
      zip(Mono.empty(), Mono.empty());

      zipWith(Mono.just(1));
      // BUG: Diagnostic matches: ARGUMENT
      zipWith(Mono.empty());
    }
  }
}

Copyright © 2017-2024 Picnic Technologies BV