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

The mapper function returned a null value. #5775

Closed
AntonLunegovPerm opened this issue Dec 22, 2017 · 5 comments
Closed

The mapper function returned a null value. #5775

AntonLunegovPerm opened this issue Dec 22, 2017 · 5 comments

Comments

@AntonLunegovPerm
Copy link

AntonLunegovPerm commented Dec 22, 2017

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)
@AntonLunegovPerm AntonLunegovPerm changed the title The mapper function returned a null value. 2.x Question The mapper function returned a null value. Dec 22, 2017
@AntonLunegovPerm AntonLunegovPerm changed the title The mapper function returned a null value. The mapper function returned a null value. '2.x' 'Question' Dec 22, 2017
@AntonLunegovPerm AntonLunegovPerm changed the title The mapper function returned a null value. '2.x' 'Question' The mapper function returned a null value. Label:2.x 'Question' Dec 22, 2017
@AntonLunegovPerm AntonLunegovPerm changed the title The mapper function returned a null value. Label:2.x 'Question' The mapper function returned a null value. '2.x' 'Question' Dec 22, 2017
@AntonLunegovPerm AntonLunegovPerm changed the title The mapper function returned a null value. '2.x' 'Question' The mapper function returned a null value. Dec 22, 2017
@akarnokd
Copy link
Member

Nulls are not allowed in 2.x. Check your mapper function why it returns null.

@AntonLunegovPerm
Copy link
Author

Thank you! I'm find the error.

@ezamelczyk
Copy link

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

@akarnokd
Copy link
Member

akarnokd commented Sep 6, 2018

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);
});

@MoustafaElsaghier
Copy link

I'm getting that a lot in my Sentry log, so is there any way to find out what is causing that, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants