-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
retrofit2 extra > NullPointerException on handling "204 No-Content" http response #1568
Comments
Probably. Contributions welcome :) |
I am experiencing the same issue. Any workaround for a quick fix? |
What about contributing like I suggested? This module is purely a contribution and I don't use Retrofit myself. |
I will try to raise the PR. |
I'm not familiar with retrofit and okhttp, but it really looks a retrofit bug to me. Please report to the retrofit project. |
@slandelle just a quick question - would you accept PR for async-http-client module or the only acceptable way for you would be fix of retrofit itself? |
@zeldigas I'd like to have retrofit authors' opinion about this issue. Has anyone reached them and/or opened an issue there (I won't)? |
got it. let me check their javadocs in more details first. I agree that it's counter intuitive to have a body object when there is no body at all, but probably it's by design and we should adjust AHC adapter for their lib... |
I'm super against pushing design mistakes and bugs on consumers instead of fixing them upstream. But then, I'm not familiar with Retrofit and there's maybe a good reason for the way it currently works. |
Heres docs for
And in our problem place we are constructing response exactly for callback, here is code excerpt from retrofit
So I'd say API is strange a bit, especially taking into account that body is marked Nullable, but javadocs explicitly says that body should not be null for responses passed to callbacks, so I'd simply fix it in AHC extra module to be more strictly compliant with retrofit/okhttp contract. |
¯_(ツ)_/¯ Also, it a pity NoContentResponseBody is package private. |
Deal, I'll send PR this week. |
Hello,
It seems that AsyncHttpClientCall.java:255 creates response body to map to OkHttp only if there was actually response in AsyncHttp call.
This unfortunately leads to NullPointerException if you try to parse 204 HTTP Response (No Content).
This happens due to the fact that Retrofit's OkHttpCall.java#L202 tries access
rawBody
w/o any null checks.Would it make sense to have
okHttpBody = ResponseBody.create(contentType, new byte[0])
in case if response was 204/205?The text was updated successfully, but these errors were encountered: