diff --git a/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractMulti.java b/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractMulti.java index 2bda7be29..1309d07c6 100644 --- a/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractMulti.java +++ b/implementation/src/main/java/io/smallrye/mutiny/operators/AbstractMulti.java @@ -1,8 +1,8 @@ package io.smallrye.mutiny.operators; import static io.smallrye.mutiny.helpers.ParameterValidation.nonNull; +import static io.smallrye.mutiny.helpers.ParameterValidation.nonNullNpe; -import java.util.Objects; import java.util.concurrent.Executor; import java.util.function.Predicate; @@ -25,11 +25,16 @@ public void subscribe(MultiSubscriber subscriber) { this.subscribe(Infrastructure.onMultiSubscription(this, subscriber)); } + @SuppressWarnings("unchecked") @Override public void subscribe(Subscriber subscriber) { - // NOTE The Reactive Streams TCK mandates throwing an NPE. - Objects.requireNonNull(subscriber, "Subscriber is `null`"); - this.subscribe(new StrictMultiSubscriber<>(subscriber)); + if (subscriber instanceof MultiOperator || subscriber instanceof StrictMultiSubscriber) { + this.subscribe((MultiSubscriber) subscriber); + } else { + // NOTE The Reactive Streams TCK mandates throwing an NPE. + nonNullNpe(subscriber, "subscriber"); + this.subscribe(new StrictMultiSubscriber<>(subscriber)); + } } @Override diff --git a/implementation/src/main/java/io/smallrye/mutiny/operators/multi/AbstractMultiOperator.java b/implementation/src/main/java/io/smallrye/mutiny/operators/multi/AbstractMultiOperator.java index ccd4c45e9..d9387c2d3 100755 --- a/implementation/src/main/java/io/smallrye/mutiny/operators/multi/AbstractMultiOperator.java +++ b/implementation/src/main/java/io/smallrye/mutiny/operators/multi/AbstractMultiOperator.java @@ -25,8 +25,4 @@ public abstract class AbstractMultiOperator extends AbstractMulti imple public AbstractMultiOperator(Multi upstream) { this.upstream = ParameterValidation.nonNull(upstream, "upstream"); } - - public Multi upstream() { - return upstream; - } }