22

I set same build types for debug and release,

buildTypes {
    debug {
        buildConfigField "String", "API_BASE_URL", "\"https://www.testUrl.com/api/\""
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release_key
    }
    release {
        buildConfigField "String", "API_BASE_URL", "\"https://www.testUrl.com/api/\""
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release_key
    }
}

But If I build with the release, I got the below error. Also, the server response is exactly same.

W/System.err: java.lang.NullPointerException: The mapper function returned a null value.
W/System.err:     at b.a.e.b.b.a(Unknown Source)
W/System.err:     at b.a.e.e.b.bs$a.onNext(Unknown Source)
W/System.err:     at b.a.e.e.b.cm$a.onNext(Unknown Source)
W/System.err:     at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(Unknown Source)
W/System.err:     at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(Unknown Source)
W/System.err:     at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(Unknown Source)
W/System.err:     at b.a.l.subscribe(Unknown Source)
W/System.err:     at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(Unknown Source)
W/System.err:     at b.a.l.subscribe(Unknown Source)
W/System.err:     at b.a.e.e.b.cm$a.a(Unknown Source)
W/System.err:     at b.a.e.e.b.cm.subscribeActual(Unknown Source)
W/System.err:     at b.a.l.subscribe(Unknown Source)
W/System.err:     at b.a.e.e.b.bs.subscribeActual(Unknown Source)
W/System.err:     at b.a.l.subscribe(Unknown Source)
W/System.err:     at b.a.e.e.b.bw.subscribeActual(Unknown Source)
W/System.err:     at b.a.l.subscribe(Unknown Source)
W/System.err:     at b.a.e.e.b.dd$b.run(Unknown Source)
W/System.err:     at b.a.s$a.run(Unknown Source)
W/System.err:     at b.a.e.g.j.run(Unknown Source)
W/System.err:     at b.a.e.g.j.call(Unknown Source)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
W/System.err:     at java.lang.Thread.run(Thread.java:761)
Expert wanna be
  • 10,218
  • 26
  • 105
  • 158
  • Can you try to reproduce the issue on a release build with proguard disabled? – Michael Dodd Dec 05 '17 at 11:34
  • @MichaelDodd Yes, it works with proguard disabled! then how it works in debug mode? it has same proguard set. could you please review my proguard-rules? – Expert wanna be Dec 05 '17 at 11:46
  • Retrofit2 [calls sometimes result in](https://github.com/square/retrofit/issues/2242#issuecomment-300850574) a `null` body which is then unconditionally forwarded to RxJava. You have to use the full `Response` instead of a direct retrieval. – akarnokd Dec 05 '17 at 12:23

1 Answers1

23

The problem comes from RxJava 2, which won't allow null values to be passed down the stream. In particularly your case, you have a mapper function, that returns a null value, which the exception clearly states.

You can reproduce that with following chunk of code:


    Observable.just(1)
              .map(integer -> null)
              .test()
              .assertError(throwable -> 
                    "The mapper function returned a null value.".equals(throwable.getMessage()));

azizbekian
  • 60,783
  • 13
  • 169
  • 249
  • 27
    The main problem though is that such a trace does not allow to know which map is returning a null value – Benoit Feb 19 '19 at 02:42
  • 2
    Actually you can handle such cases. For more info see article: https://rongi.github.io/kotlin-blog/rxjava/2017/09/25/breadcrumbs-rxjava-error-handling.html – cosic Jul 30 '19 at 20:51
  • 7
    1. I don't understand how this question was marked duplicate. 2. I don't understand how there is not an answer to this question that helps find which map is returning a null value. – nbroeking Nov 22 '19 at 22:17
  • 1
    Handling null in RxJava 2.0: https://medium.com/@joshfein/handling-null-in-rxjava-2-0-10abd72afa0b – RefuX May 29 '20 at 15:56
  • @RefuX: "I don't understand how this question was marked duplicate." Hmm, a lot of good questions are marked as duplicate. It is based on the laziness of the reviewers - they react just to known keywords :( I marked the question to Reopen, please join me. – Honza Zidek Jan 31 '22 at 15:58