question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException in Http1ExchangeCodec.readResponseHeaders() in OkHttp 3.14.0

See original GitHub issue

Since 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:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
Rolf-Smitcommented, Apr 9, 2019

Experiencing the same issue.

1reaction
swankjessecommented, May 19, 2019

3.14.2 is out and has this fix. Go get it!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found