Thanks for this library!
I upgraded RxJava to 2.x in my Android app and now I get an error:
NullPointerException: the mapper function returned a null value. Exception is thrown by ObjectHelper.
It appear inside this part of code (FlowableMap.java):
return t != null ? ObjectHelper.<U>requireNonNull(mapper.apply(t), "The mapper function returned a null value.") : null;
Seems that mapper.apply(t) return null...
I call onNext using enum object
public class SystemBus {
private PublishProcessor<SystemEvent> mSystemEventPublishSubject;
SystemBus() {
mSystemEventPublishSubject = PublishProcessor.create();
}
public void onNext(SystemEvent systemEvent) {
mSystemEventPublishSubject.onNext(systemEvent); // ---> this line lead to an error
}
public PublishProcessor<SystemEvent> getObservable() {
return mSystemEventPublishSubject;
}
}
Also SystemEvent class :
public enum SystemEvent {
FINISH_ACTIVITY,
PERMISSIONS_REQUEST,
PERMISSIONS_RESPONSE,
UPDATE_CARDS,
PDL,
MENU_REFRESH
}
Here the stack trace:
Fatal Exception: io.reactivex.exceptions.OnErrorNotImplementedException: The mapper function returned a null value.
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
at io.reactivex.internal.subscribers.LambdaSubscriber.onError(LambdaSubscriber.java:79)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.onError(BasicFuseableSubscriber.java:101)
at io.reactivex.internal.subscribers.BasicFuseableConditionalSubscriber.onError(BasicFuseableConditionalSubscriber.java:100)
at io.reactivex.internal.subscribers.BasicFuseableConditionalSubscriber.fail(BasicFuseableConditionalSubscriber.java:110)
at io.reactivex.internal.operators.flowable.FlowableMap$MapConditionalSubscriber.tryOnNext(FlowableMap.java:126)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterConditionalSubscriber.tryOnNext(FlowableFilter.java:141)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterConditionalSubscriber.onNext(FlowableFilter.java:119)
at io.reactivex.processors.PublishProcessor$PublishSubscription.onNext(PublishProcessor.java:315)
at io.reactivex.processors.PublishProcessor.onNext(PublishProcessor.java:197)
at ai.#####.SystemBus.onNext(SystemBus.java:20)
at ai.#####.App$2.onReceive(App.java:151)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:922)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by java.lang.NullPointerException: The mapper function returned a null value.
at io.reactivex.internal.functions.ObjectHelper.requireNonNull(ObjectHelper.java:39)
at io.reactivex.internal.operators.flowable.FlowableMap$MapConditionalSubscriber.tryOnNext(FlowableMap.java:124)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterConditionalSubscriber.tryOnNext(FlowableFilter.java:141)
at io.reactivex.internal.operators.flowable.FlowableFilter$FilterConditionalSubscriber.onNext(FlowableFilter.java:119)
at io.reactivex.processors.PublishProcessor$PublishSubscription.onNext(PublishProcessor.java:315)
at io.reactivex.processors.PublishProcessor.onNext(PublishProcessor.java:197)
at ai.#####.SystemBus.onNext(SystemBus.java:20)
at ai.#####.App$2.onReceive(App.java:151)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:922)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Nulls are not allowed in 2.x. Check your mapper function why it returns null.
Thank you! I'm find the error.
Maybe add better logging to this? I have multiple streams running in background and can't pinpoint where is this mapper function returning null value
You could use the function tagging support in the extensions project, or simply define your lambdas in a way that throw on null return:
source.map(v -> {
// some computation
return Objects.requireNonNull(result);
});
Most helpful comment
Nulls are not allowed in 2.x. Check your mapper function why it returns null.