Skip to content

Instantly share code, notes, and snippets.

@adamsp
Created February 5, 2014 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamsp/7ffd33906abf9b1a5df3 to your computer and use it in GitHub Desktop.
Save adamsp/7ffd33906abf9b1a5df3 to your computer and use it in GitHub Desktop.
Logcat messages when trying to use latest OkHttp build (as at this commit: https://github.com/square/okhttp/commit/85fbb0abeb6d94ba963ea4302be02035a1563927). Built using 'mvn package -DskipTests' as I can't get the tests to pass.
02-06 10:42:17.732: I/dalvikvm(1549): Could not find method com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getContentLengthLong, referenced from method com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.getContentLengthLong
02-06 10:42:17.732: W/dalvikvm(1549): VFY: unable to resolve virtual method 1361: Lcom/squareup/okhttp/internal/http/HttpURLConnectionImpl;.getContentLengthLong ()J
02-06 10:42:17.732: D/dalvikvm(1549): VFY: replacing opcode 0x6e at 0x0002
02-06 10:42:17.732: I/dalvikvm(1549): Could not find method com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getHeaderFieldLong, referenced from method com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.getHeaderFieldLong
02-06 10:42:17.732: W/dalvikvm(1549): VFY: unable to resolve virtual method 1374: Lcom/squareup/okhttp/internal/http/HttpURLConnectionImpl;.getHeaderFieldLong (Ljava/lang/String;J)J
02-06 10:42:17.732: D/dalvikvm(1549): VFY: replacing opcode 0x6e at 0x0002
02-06 10:42:18.552: D/dalvikvm(1549): GC_FOR_ALLOC freed 306K, 5% free 7986K/8328K, paused 21ms, total 21ms
02-06 10:42:18.852: W/dalvikvm(1549): threadid=16: thread exiting with uncaught exception (group=0x419eeba8)
02-06 10:42:18.852: E/AndroidRuntime(1549): FATAL EXCEPTION: Twitter Stream consumer-1[Establishing connection]
02-06 10:42:18.852: E/AndroidRuntime(1549): Process: nz.net.speakman.android.dreamintweets, PID: 1549
02-06 10:42:18.852: E/AndroidRuntime(1549): java.lang.NullPointerException
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.internal.bytes.ByteString.of(ByteString.java:49)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.internal.Platform$Android.getNpnSelectedProtocol(Platform.java:296)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.Connection.upgradeToTls(Connection.java:153)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.Connection.connect(Connection.java:94)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:245)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:190)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:372)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:97)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:210)
02-06 10:42:18.852: E/AndroidRuntime(1549): at com.squareup.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:213)
02-06 10:42:18.852: E/AndroidRuntime(1549): at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:135)
02-06 10:42:18.852: E/AndroidRuntime(1549): at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
02-06 10:42:18.852: E/AndroidRuntime(1549): at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
02-06 10:42:18.852: E/AndroidRuntime(1549): at twitter4j.TwitterStreamImpl.getUserStream(TwitterStreamImpl.java:228)
02-06 10:42:18.852: E/AndroidRuntime(1549): at twitter4j.TwitterStreamImpl$5.getStream(TwitterStreamImpl.java:200)
02-06 10:42:18.852: E/AndroidRuntime(1549): at twitter4j.TwitterStreamImpl$TwitterStreamConsumer.run(TwitterStreamImpl.java:462)
@adamsp
Copy link
Author

adamsp commented Feb 5, 2014

The following was tested on a 2012 Nexus 7 running factory 4.4.2. Similar tests on a 4.3 Genymotion image resulted in no issues and immediate closure of the stream (which was the original problem), even when setting OkHttp as the stream handler the same stack trace (forgot I was only setting OkHttp for 4.4+).

The above stack trace began occurring in this commit - the stack trace shows the throw at line 295 of Platform.java in this commit. The getNpnSelectedProtocol.invoke call is returning null, causing the ByteString.of call to throw.

If we look further up the Platform class, we can see that getNpnSelectedProtocol is being called on org.conscrypt.OpenSSLSocketImpl, or on org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl:

      try {
        openSslSocketClass = Class.forName("com.android.org.conscrypt.OpenSSLSocketImpl");
      } catch (ClassNotFoundException ignored) {
        // Older platform before being unbundled.
        openSslSocketClass = Class.forName(
            "org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl");
      }

...

  getNpnSelectedProtocol = openSslSocketClass.getMethod("getNpnSelectedProtocol");

The docs for getNpnSelectedProtocol on line 1427 of the conscrypt OpenSSLSocketImpl source and on line 956 of the apache OpenSSLSocketImpl imply that "no protocol is agreed upon" - I'm not sure what this means, but it returns null in this case, and OkHttp isn't handling that.

@swankjesse
Copy link

Thanks for digging into this @adamsp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment