Okhttp: NullPointerException in Http1ExchangeCodec.readResponseHeaders() in OkHttp 3.14.0

Created on 9 Apr 2019  路  11Comments  路  Source: square/okhttp

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.

bug

Most helpful comment

Experiencing the same issue.

All 11 comments

Experiencing the same issue.

I鈥檒l cut a 3.14.2 release for this.

@swankjesse what's the ETA for 3.14.2?

Facing the same issue. @swankjesse Please provide an update on 3.14.2

Any update please? We've been holding back all upgrades to the OkHttp dependencies because of this bug.

Lemme get on this.

Any ETA for the 3.14.2 release?

Soon!

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

hi @swankjesse can this fix be cherry picked to 3.12.x? thanks!

@andrlee no. This bug didn't exist until 3.14.0.

Was this page helpful?
0 / 5 - 0 ratings