NestedPublishers

WARNING

FragileCode

View source code on GitHub

Summary

Avoid Publishers that emit other Publisherss; the resultant code is hard to reason about

Suppression

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

Disable this pattern completely by adding -Xep:NestedPublishers: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 org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.GroupedFlux;
import reactor.core.publisher.Mono;

class A {
  void m() {
    Mono.empty();
    Flux.just(1);
    Flux.just(1, 2).groupBy(i -> i).map(groupedFlux -> (GroupedFlux) groupedFlux);

    // BUG: Diagnostic contains:
    Mono.just(Mono.empty());
    // BUG: Diagnostic contains:
    Flux.just(Flux.empty());
    // BUG: Diagnostic contains:
    Mono.just((Flux) Flux.just(1));
    // BUG: Diagnostic contains:
    Flux.just((Publisher) Mono.just(1));
    // BUG: Diagnostic contains:
    Mono.just(1).map(Mono::just);
  }
}

Copyright © 2017-2024 Picnic Technologies BV