You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While flatMap and concatMap are fine with flattening null values, concatMapEager blows up.
import rx.Observable;
public class RxJavaNullValueTolerance {
public static void main(String[] args) {
Observable.just("just me")
.flatMap(nextString -> Observable.just(null))
.subscribe(nextObject -> System.out.println("Got: " + nextObject));
System.out.println("flatMap is fine with null values");
Observable.just("just me")
.concatMap(nextString -> Observable.just(null))
.subscribe(nextObject -> System.out.println("Got: " + nextObject));
System.out.println("concatMap is fine with null values");
Observable.just("just me")
.concatMapEager(nextString -> Observable.just(null))
.subscribe(nextObject -> System.out.println("Got: " + nextObject));
System.out.println("concatMapEager is fine with null values");
}
}
(RxJava 1.1.0)
Output:
Got: null
flatMap is fine with null values
Got: null
concatMap is fine with null values
Exception in thread "main" rx.exceptions.OnErrorNotImplementedException: null elements not allowed
at rx.Observable$27.onError(Observable.java:7923)
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:159)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:120)
at rx.internal.operators.OperatorEagerConcatMap$EagerOuterSubscriber.drain(OperatorEagerConcatMap.java:216)
at rx.internal.operators.OperatorEagerConcatMap$EagerInnerSubscriber.onError(OperatorEagerConcatMap.java:302)
at rx.Observable.unsafeSubscribe(Observable.java:8105)
at rx.internal.operators.OperatorEagerConcatMap$EagerOuterSubscriber.onNext(OperatorEagerConcatMap.java:144)
at rx.internal.util.ScalarSynchronousObservable$1.call(ScalarSynchronousObservable.java:46)
at rx.internal.util.ScalarSynchronousObservable$1.call(ScalarSynchronousObservable.java:35)
at rx.Observable$2.call(Observable.java:162)
at rx.Observable$2.call(Observable.java:154)
at rx.Observable.subscribe(Observable.java:8191)
at rx.Observable.subscribe(Observable.java:8158)
at rx.Observable.subscribe(Observable.java:7914)
at RxJavaNullValueTolerance.main(RxJavaNullValueTolerance.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.NullPointerException: null elements not allowed
at rx.internal.util.unsafe.SpscArrayQueue.offer(SpscArrayQueue.java:104)
at rx.internal.operators.OperatorEagerConcatMap$EagerInnerSubscriber.onNext(OperatorEagerConcatMap.java:294)
at rx.internal.util.ScalarSynchronousObservable$1.call(ScalarSynchronousObservable.java:46)
at rx.internal.util.ScalarSynchronousObservable$1.call(ScalarSynchronousObservable.java:35)
at rx.Observable.unsafeSubscribe(Observable.java:8098)
... 14 more
This is IMO critical, since these three operators are closely related and often replaced thru each other, depending on the concrete "flattening" requirements.
The text was updated successfully, but these errors were encountered:
While flatMap and concatMap are fine with flattening null values, concatMapEager blows up.
(RxJava 1.1.0)
Output:
This is IMO critical, since these three operators are closely related and often replaced thru each other, depending on the concrete "flattening" requirements.
The text was updated successfully, but these errors were encountered: