NullPointerException in Http1ExchangeCodec.readResponseHeaders() in OkHttp 3.14.0
See original GitHub issueSince upgrading OkHttp from 3.13.1 to 3.14.0 in our Android app, some of our users experience crashes because of a NullPointerException in Http1ExchangeCodec
line 233.
Relevant stacktrace:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'okhttp3.Route okhttp3.internal.connection.RealConnection.route()' on a null object reference
at okhttp3.internal.http1.Http1ExchangeCodec.readResponseHeaders(Http1ExchangeCodec.java:233)
at okhttp3.internal.connection.RealConnection.createTunnel(RealConnection.java:400)
at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.java:236)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:177)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:224)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:107)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:87)
at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:162)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
...
The majority of the crashes occur on Motorola devices. We have not been able to reproduce the issue on a test device, but it seems related to the app forcing a request over WiFi, and users having a proxy set on the device.
The cause of the NullPointerException is easy to find from the stacktrace, though. From RealConnection:
Http1ExchangeCodec tunnelCodec = new Http1ExchangeCodec(null, null, source, sink);
source.timeout().timeout(readTimeout, MILLISECONDS);
sink.timeout().timeout(writeTimeout, MILLISECONDS);
tunnelCodec.writeRequest(tunnelRequest.headers(), requestLine);
tunnelCodec.finishRequest();
Response response = tunnelCodec.readResponseHeaders(false)
.request(tunnelRequest)
.build();
The second argument to Http1ExchangeCodec()
(realConnection) is passed as null
, which causes readResponseHeaders()
to throw a NullPointerException when an EOFException is encountered.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:11
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Failed to process okhttp-3.14.0.jar - Stack Overflow
Trying to follow along a course on teamtreehouse on building an android weather app. The teacher is able get there app to run...
Read more >3.x Change Log - OkHttp
Fix: Don't crash with a NullPointerException when formatting an error message describing a truncated response from an HTTPS proxy.
Read more >Protocol (OkHttp 3.14.2 API) - Javadoc.io
Returns the protocol identified by protocol . String · toString(). Returns the string used to identify this protocol for ALPN, like "http/1.1 ...
Read more >NullPointerException (Java Platform SE 7 ) - Oracle Help Center
public class NullPointerException extends RuntimeException. Thrown when an application attempts to use null in a case where an object is required.
Read more >record cannot be null" in pipeline with Oracle CDC Client Origin
NullPointerException at com.streamsets.pipeline.stage.origin.jdbc.cdc.oracle.OracleCDCSource.addRecordsToQueue(OracleCDCSource.java:1165) at ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Experiencing the same issue.
3.14.2 is out and has this fix. Go get it!