RxJava icon indicating copy to clipboard operation
RxJava copied to clipboard

2.x: NullPointerException in FlowableToList$ToListSubscriber.onNext

Open dvasko opened this issue 9 years ago • 6 comments

Notices few of this crashes, is there any way to find from where they are coming?

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.Collection.add(java.lang.Object)' on a null object reference
       at io.reactivex.internal.operators.flowable.FlowableToList$ToListSubscriber.onNext(FlowableToList.java:71)
       at io.reactivex.internal.operators.flowable.FlowableFilter$FilterSubscriber.tryOnNext(FlowableFilter.java:73)
       at io.reactivex.internal.operators.flowable.FlowableFilter$FilterSubscriber.onNext(FlowableFilter.java:51)
       at io.reactivex.internal.operators.flowable.FlowableConcatMap$ConcatMapImmediate.innerNext(FlowableConcatMap.java:215)
       at io.reactivex.internal.operators.flowable.FlowableConcatMap$ConcatMapInner.onNext(FlowableConcatMap.java:592)
       at io.reactivex.internal.operators.flowable.FlowableFromIterable$IteratorSubscription.fastPath(FlowableFromIterable.java:181)
       at io.reactivex.internal.operators.flowable.FlowableFromIterable$BaseRangeSubscription.request(FlowableFromIterable.java:123)
       at io.reactivex.internal.subscriptions.SubscriptionArbiter.setSubscription(SubscriptionArbiter.java:96)
       at io.reactivex.internal.operators.flowable.FlowableConcatMap$ConcatMapInner.onSubscribe(FlowableConcatMap.java:585)
       at io.reactivex.internal.operators.flowable.FlowableFromIterable.subscribe(FlowableFromIterable.java:69)
       at io.reactivex.internal.operators.flowable.FlowableFromIterable.subscribeActual(FlowableFromIterable.java:47)
       at io.reactivex.Flowable.subscribe(Flowable.java:12901)
       at io.reactivex.internal.operators.flowable.FlowableConcatMap$ConcatMapImmediate.drain(FlowableConcatMap.java:343)
       at io.reactivex.internal.operators.flowable.FlowableConcatMap$BaseConcatMapSubscriber.onNext(FlowableConcatMap.java:158)
       at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.onNext(FlowableSubscribeOn.java:97)
       at io.reactivex.internal.subscriptions.DeferredScalarSubscription.complete(DeferredScalarSubscription.java:133)
       at io.reactivex.internal.operators.flowable.FlowableFromCallable.subscribeActual(FlowableFromCallable.java:44)
       at io.reactivex.Flowable.subscribe(Flowable.java:12901)
       at io.reactivex.internal.operators.flowable.FlowableSubscribeOn$SubscribeOnSubscriber.run(FlowableSubscribeOn.java:82)
       at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:59)
       at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:51)
       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
       at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)

dvasko avatar Mar 31 '17 08:03 dvasko

What version are you using? Could you share some code?

akarnokd avatar Mar 31 '17 08:03 akarnokd

version 2.0.6 this is one of the examples

        Flowable<List<Team>> networkTask = Network.getUiClient().getTeams()
                .onErrorReturn(throwable -> new ArrayList<>())
                .concatMap(Flowable::fromIterable)
                .filter(team -> isValid(team))
                .toList().toFlowable();

dvasko avatar Mar 31 '17 09:03 dvasko

I'd guess Network.getUiClient().getTeams() is a custom Publisher of some sorts because that particular exception can only happen if there is an onNext after an onComplete or onError. It would be great if you could write a standalone unit test that reproduces the problem.

akarnokd avatar Mar 31 '17 09:03 akarnokd

Behind Network.getUiClient().getTeams() and every other network call is Retrofit, beside that we have few database calls wraped in Flowable.fromCallable(db::getTeams); and no other custom Publisher. We see bug happening in production but we can't reproduce it and stacktrace don't give to much informations from where is coming from (Network API have ~50 endpoints). Only thing that we know is that bug is affecting really small number of sessions.

dvasko avatar Mar 31 '17 10:03 dvasko

There is a small race window between an onNext() and a cancel() that could cause this. I'll post a fix for this.

akarnokd avatar Mar 31 '17 10:03 akarnokd

Closing via #5247.

akarnokd avatar Mar 31 '17 17:03 akarnokd