retrofit icon indicating copy to clipboard operation
retrofit copied to clipboard

BodyObservable: when null value slips into RxJava2 NPE is not propagated to onError()

Open southerton81 opened this issue 4 years ago • 0 comments

When the response came with empty body, Retrofit BodyObservable calls onNext() with null value. In RxJava2 that leads to NPE, but that is not an issue, and there's a recommended way to deal with it using Completable or Optional converter (https://github.com/square/retrofit/issues/2242).

The problem I have encountered is that onError() and doFinally() handlers are not triggered at all, so that observable silently fails when getting NPE (making it harder to spot and fix). I've managed to isolate this case:

https://gist.github.com/southerton81/7cdbfd10c59c7b58b7ad468c27dcb9b0

southerton81 avatar Jul 02 '20 11:07 southerton81