Skip to content

The mapper function returned a null value.  #5775

Closed

Description

@AntonLunegovPerm

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)

Activity

  1. changed the title [-]The mapper function returned a null value. `2.x` `Question`[/-] [+]The mapper function returned a null value. [/+] on Dec 22, 2017
  2. changed the title [-]The mapper function returned a null value. [/-] [+]The mapper function returned a null value. '2.x' 'Question'[/+] on Dec 22, 2017
  3. changed the title [-]The mapper function returned a null value. '2.x' 'Question'[/-] [+]The mapper function returned a null value. Label:2.x 'Question'[/+] on Dec 22, 2017
  4. changed the title [-]The mapper function returned a null value. Label:2.x 'Question'[/-] [+]The mapper function returned a null value. '2.x' 'Question'[/+] on Dec 22, 2017
  5. changed the title [-]The mapper function returned a null value. '2.x' 'Question'[/-] [+]The mapper function returned a null value. [/+] on Dec 22, 2017
  6. akarnokd commented on Dec 22, 2017

    @akarnokd
    Member

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

  7. AntonLunegovPerm commented on Dec 22, 2017

    @AntonLunegovPerm
    Author

    Thank you! I'm find the error.

  8. ezamelczyk commented on Sep 6, 2018

    @ezamelczyk

    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

  9. akarnokd commented on Sep 6, 2018

    @akarnokd
    Member

    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);
    });
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions