FluxImplicitBlock

WARNING

Concurrency

Performance

View source code on GitHub

Summary

Avoid iterating over Fluxes in an implicitly blocking manner

Suppression

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

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

Samples

Replacement

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

 import reactor.core.publisher.Flux;
 
 class A {
+  @SuppressWarnings("FluxImplicitBlock")
   void m() {
     Flux.just(1).toIterable();
     Flux.just(2).toStream();
   }
 }
 
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
 import reactor.core.publisher.Flux;
 
 class A {
   void m() {
-    Flux.just(1).toIterable();
-    Flux.just(2).toStream();
-    Flux.just(3).toIterable().iterator();
-    Flux.just(4).toStream().count();
-    Flux.just(5) /* a */./* b */ toIterable /* c */(/* d */ ) /* e */;
-    Flux.just(6) /* a */./* b */ toStream /* c */(/* d */ ) /* e */;
+    Flux.just(1).collect(toImmutableList()).block();
+    Flux.just(2).collect(toImmutableList()).block().stream();
+    Flux.just(3).collect(toImmutableList()).block().iterator();
+    Flux.just(4).collect(toImmutableList()).block().stream().count();
+    Flux.just(5).collect(toImmutableList()).block() /* e */;
+    Flux.just(6).collect(toImmutableList()).block().stream() /* e */;
   }
 }
 
+import static java.util.stream.Collectors.toList;
+
 import reactor.core.publisher.Flux;
 
 class A {
   void m() {
-    Flux.just(1).toIterable();
-    Flux.just(2).toStream();
-    Flux.just(3).toIterable().iterator();
-    Flux.just(4).toStream().count();
-    Flux.just(5) /* a */./* b */ toIterable /* c */(/* d */ ) /* e */;
-    Flux.just(6) /* a */./* b */ toStream /* c */(/* d */ ) /* e */;
+    Flux.just(1).collect(toList()).block();
+    Flux.just(2).collect(toList()).block().stream();
+    Flux.just(3).collect(toList()).block().iterator();
+    Flux.just(4).collect(toList()).block().stream().count();
+    Flux.just(5).collect(toList()).block() /* e */;
+    Flux.just(6).collect(toList()).block().stream() /* e */;
   }
 }
 

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 com.google.common.collect.ImmutableList;
import java.util.stream.Stream;
import reactor.core.publisher.Flux;

class A {
  void m() {
    // BUG: Diagnostic matches: X
    Flux.just(1).toIterable();
    // BUG: Diagnostic matches: X
    Flux.just(2).toStream();
    // BUG: Diagnostic matches: X
    long count = Flux.just(3).toStream().count();

    Flux.just(4).toIterable(1);
    Flux.just(5).toIterable(2, null);
    Flux.just(6).toStream(3);
    new Foo().toIterable();
    new Foo().toStream();
  }

  class Foo<T> {
    Iterable<T> toIterable() {
      return ImmutableList.of();
    }

    Stream<T> toStream() {
      return Stream.empty();
    }
  }
}
import reactor.core.publisher.Flux;

class A {
  void m() {
    // BUG: Diagnostic matches: X
    Flux.just(1).toIterable();
    // BUG: Diagnostic matches: X
    Flux.just(2).toStream();
  }
}

Copyright © 2017-2024 Picnic Technologies BV