Okhttp: 3.12.9 Regression: java.lang.VerifyError on Android 4.3 and earlier

Created on 26 Feb 2020  路  4Comments  路  Source: square/okhttp

The 3.12 backport for #5816 contains a catch block which references the ReflectiveOperationException type. ReflectiveOperationException was not introduced until KitKat, so this catch block causes class initialization to fail on earlier versions of Android. In my case, I reproduced the bug using an Android 4.1 image in the Android Studio emulator.

Reproducer:

new OkHttpClient.Builder().build();

Exception:

02-25 21:08:51.091 2696-2696/com.example.okhttptest W/dalvikvm: VFY: unable to resolve exception class 74 (Ljava/lang/ReflectiveOperationException;)
02-25 21:08:51.091 2696-2696/com.example.okhttptest W/dalvikvm: VFY: unable to find exception handler at addr 0x15
02-25 21:08:51.101 2696-2696/com.example.okhttptest W/dalvikvm: VFY:  rejected Lokhttp3/internal/platform/Android10Platform;.buildIfSupported ()Lokhttp3/internal/platform/Platform;
02-25 21:08:51.101 2696-2696/com.example.okhttptest W/dalvikvm: VFY:  rejecting opcode 0x0d at 0x0015
02-25 21:08:51.101 2696-2696/com.example.okhttptest W/dalvikvm: VFY:  rejected Lokhttp3/internal/platform/Android10Platform;.buildIfSupported ()Lokhttp3/internal/platform/Platform;
02-25 21:08:51.111 2696-2696/com.example.okhttptest W/dalvikvm: Verifier rejected class Lokhttp3/internal/platform/Android10Platform;
02-25 21:08:51.111 2696-2696/com.example.okhttptest W/dalvikvm: Exception Ljava/lang/VerifyError; thrown while initializing Lokhttp3/internal/platform/Platform;
02-25 21:08:51.111 2696-2696/com.example.okhttptest D/AndroidRuntime: Shutting down VM
02-25 21:08:51.121 2696-2696/com.example.okhttptest W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x9e52d2a0)
02-25 21:08:51.131 2696-2696/com.example.okhttptest E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.ExceptionInInitializerError
        at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:292)
        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:258)
        at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1040)
        at com.example.okhttptest.MainActivity.onCreate(MainActivity.java:14)
        at android.app.Activity.performCreate(Activity.java:5008)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        at android.app.ActivityThread.access$600(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.VerifyError: okhttp3/internal/platform/Android10Platform
        at okhttp3.internal.platform.Platform.findPlatform(Platform.java:201)
        at okhttp3.internal.platform.Platform.<clinit>(Platform.java:78)
        at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:292)聽
        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:258)聽
        at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1040)聽
        at com.example.okhttptest.MainActivity.onCreate(MainActivity.java:14)聽
        at android.app.Activity.performCreate(Activity.java:5008)聽
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)聽
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)聽
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)聽
        at android.app.ActivityThread.access$600(ActivityThread.java:130)聽
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)聽
        at android.os.Handler.dispatchMessage(Handler.java:99)聽
        at android.os.Looper.loop(Looper.java:137)聽
        at android.app.ActivityThread.main(ActivityThread.java:4745)聽
        at java.lang.reflect.Method.invokeNative(Native Method)聽
        at java.lang.reflect.Method.invoke(Method.java:511)聽
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)聽
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)聽
        at dalvik.system.NativeStart.main(Native Method)聽
bug

Most helpful comment

Fixed in 3.12.10

All 4 comments

Damn. Sorry. Thanks for raising. I tested on 5.0. Will fix and retest.

Fixed here https://github.com/square/okhttp/pull/5827

cc @swankjesse

@cgutman Thanks for raising so quickly.

Fixed in 3.12.10

Was this page helpful?
0 / 5 - 0 ratings