Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concatMapEager blows up on null values #3629

Closed
Petikoch opened this issue Jan 21, 2016 · 4 comments
Closed

concatMapEager blows up on null values #3629

Petikoch opened this issue Jan 21, 2016 · 4 comments
Labels

Comments

@Petikoch
Copy link

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.

@Petikoch
Copy link
Author

@akarnokd what do you think about this one? Best regards, Peti

@akarnokd akarnokd added the Bug label Jan 21, 2016
@akarnokd
Copy link
Member

Yes, this is yet another oversight in eager concatMap. I'll post the fix soon.

@Petikoch
Copy link
Author

@akarnokd , thanks a lot!

@zsxwing
Copy link
Member

zsxwing commented Jan 22, 2016

Fixed in #3630

@zsxwing zsxwing closed this as completed Jan 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants