-
Notifications
You must be signed in to change notification settings - Fork 1.1k
OkHttp3 Interceptor crash #346
Comments
This looks like the same issue as with okhttp2, you may have accidentally used a regular interceptor instead of a network interceptor. I keep forgetting to actually fix this with a proper error message :( |
I did notice that there are two methods for adding an interceptor when building an
|
Hmm, then I'm puzzled. @swankjesse? |
The interceptor might be returning a null connection after that physical connection has been released back to the pool. Perhaps the response has a |
I am facing the same crash here.
Please note that since OkHttp3, you can't add the interceptor with Could the crash be related to this? My device is connected since I can use Vysor and debug the app through the same connection, so it's not a connection issue. |
@kypeli your crash is unrelated. |
@jasta Thanks for the clarification. I see the same stack trace or null pointer exception, so must be the same issue as described in this ticket. Hopefully fixed soon :) |
Hello, we've merged in a change that should resolve this that will be going out with OkHttp 3.3. |
I also face the same crash:
It happens when a http request returns 204 and has no response body. I debuged, as above said, it was caused by null connection(). I use stetho 1.3.1 and retrofit 2.0 (it depends okhttp 3.2.0) |
@baurine can you test with okhttp 3.3 to verify that the upstream fix works? I don't think this is necessarily a Stetho issue. |
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference compile 'com.facebook.stetho:stetho:1.3.1' OkHttpClient.Builder builder = new OkHttpClient.Builder(); |
@jasta I have the same problem and did some digging. The source of the crash is that
The fix that @swankjesse made for #2288 fixes the crash that @baurine saw but doesn't fix the case of I also noticed that we only need the connection object to compute a hash code that will become the connection ID, so maybe we don't even need a reference to the connection in the first place. Is there a chance we can replace it by something else (e.g. a counter or some random number)? |
Yikes. I’ll fix this one too. |
(Or more specifically, I’ll ask @dave-r12 to fix it!) |
@Baleizao I do not see that RealCall has a connection() method. I think you might be referring to the ApplicationInterceptorChain class? That class handles Application interceptors, which are different than network interceptors (see https://github.com/square/okhttp/wiki/Interceptors). Stetho is using a network interceptor, so that class should not matter. |
Gah... you're absolutely right! I accidentally installed the |
Yes, it is. it is worked by using |
@jasta so so sorry, I just remember the thing you asked me to do. but I can't find okhttp 3.3, the latest version is still 3.2.0. I tried
One more thing, I updated the android studio from 1.5 to 2.1 stable, debug my project again, and this bug didn't reproduce, I tried many times. It is a little strange. |
@baurine According to OkHttp's README:
So, you just need to add the repository url to your gradle script repositories section.
|
@juandiana thank you! it works. Now I used the okhttp 3.3, test again, the crash has not happened again. but my develop environment is not as same as before, I updated the android studio from 1.5 to 2.1. any way, if I meet this bug again, I will report. |
Can this issue be closed out? It looks like the thread has settled a bit and okhttp 3.3 is indeed confirmed to fix, yes? |
I was using okhttp as transitive dependency from retrofit2 and this crash happened to me as well. After including direct dependency to okhttp:3.4.2 it is no longer happening. |
A null check has been committed on master, but no release has been made after 1.5.0 yet. |
When are we expecting the null check on master to be updated into a 1.5.1 release? We're blocked using stetho's network feature because of the crash fixed with @cristan's commit. |
Is your interceptor registered as a network interceptor? #549 provides a better error message when you're incorrectly registered as a vanilla interceptor. |
We don't actually want folks using StethoInterceptor as an app interceptor (instead of a network interceptor), so we've gone further and are now just throiwng a clear error message to this effect. See #584. |
App Crashes when the request is cancelled and the interceptor return NULL. In my code, "Cancelled" exception was caught, return NULL or re-throw the exception cause the app crash.
|
I just upgraded OkHttp to version 3.0.1 and Stetho to version 1.3.0 (and its corresponding new OkHttp3 network interceptor).
I'm experiencing the following NullPointerException when inspecting HTTP traffic:
The text was updated successfully, but these errors were encountered: