ReactiveX / RxJava

RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
Apache License 2.0
47.84k stars 7.61k forks source link

java.lang.NullPointerException: Attempt to invoke interface method 'boolean io.reactivex.internal.fuseable.SimpleQueue.isEmpty()' on a null object reference #5435

Closed ivnsch closed 7 years ago

ivnsch commented 7 years ago

I get this exception sometimes. It can't be reproduced reliably. Can't find any reference to my code, so I have no idea what's causing it:

java.lang.IllegalStateException: Fatal Exception thrown on Scheduler. at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:113) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean io.reactivex.internal.fuseable.SimpleQueue.isEmpty()' on a null object reference at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:172) at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:252) at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:111) at android.os.Handler.handleCallback(Handler.java:751)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6119)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

Any ideas...?

akarnokd commented 7 years ago

Please check your application for the use of Observable.unsafeCreate or extends Observable as possible candidates.

ivnsch commented 7 years ago

I haven't any of these... (I'm also 110% sure as I developed the app from scratch and don't even know how to use them. I did a text search anyway).

Maybe com.jakewharton.rxbinding2:rxbinding-kotlin:2.0.0 could be responsible? I see some of them there and it's the only dependency that could be causing this.

akarnokd commented 7 years ago

My guess is this line in the Rx binding. If you subscribe off the main thread, the error path doesn't properly initialize the stream and you get an NPE.

ivnsch commented 7 years ago

I think I'm doing all my UI operations using the main thread scheduler, but will review.

Anyway, how can I debug to confirm this (if possible not having to put breakpoints in rxbinding-kotlin)? The exception you linked to is nowhere to be seen in the stacktrace...

akarnokd commented 7 years ago

Place a breakpoint on that method.

/cc @JakeWharton

ivnsch commented 7 years ago

heh, I just edited my last comment with "if possible not having to put breakpoints in rxbinding-kotlin"... I'll do it... but am curious in general how to debug this kind of things. I mean, if you weren't helping me I wouldn't have an idea about where to put the breakpoint...

akarnokd commented 7 years ago

This is the trouble with omitting an onSubscribe in a sequence that goes async. I'd modify one of the debug support implementation with protocol verification.

ivnsch commented 7 years ago

@akarnokd Ok, I got it, I forgot to use the main thread scheduler in a call, which at some point calls rx bindings. It's triggered in the line you linked to. I found this using the breakpoint - enabling debug support didn't have an apparent effect and the stacktrace was the same as before... probably I need to dive more into it to understand how to use it.

akarnokd commented 7 years ago

I've posted the issue on RxBinding. I'll also think about adding some additional debug support in RxJava2Extensions to help detecting such cases.

ivnsch commented 7 years ago

Thanks!