spring-webfluxreactivewebflux

Why can't a Mono hold a NULL


Mono.just(null) will not compile. Why is that?

On a procedural level I get it. It does not make sense to have a processing queue without something to process. Can someone phrase this for me with some more technical depth?


Solution

  • As stipulated by Reactive-Streams, rule 2.13:

    Calling onSubscribe, onNext, onError or onComplete MUST return normally except when any provided parameter is null in which case it MUST throw a java.lang.NullPointerException to the caller, for all other

    And Reactor is based on the Reactive Streams.

    Personally, I don’t like this rule, but the rule is not set by me. Since I want to use it, I can only follow it.

    I guess Flux is the core of the Reactor, Mono is incidental. For streams, banning null is probably a reasonable option although it would be inconvenient for Mono.