Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalStateException: reasonPhrase can't be empty with Android WebView

I've recently been noticing that a number of users are receiving this IllegalStateException, which causes a crash of the app. It happens when a WebView is shown to the user:

Fatal Exception: java.lang.IllegalArgumentException: reasonPhrase can't be empty.
       at android.webkit.WebResourceResponse.setStatusCodeAndReasonPhrase + 129(WebResourceResponse.java:129)
       at android.webkit.WebResourceResponse.(WebResourceResponse.java:70)
       at jY.a + 308(jY.java:308)
       at zn.handleMessage + 67(zn.java:67)
       at android.os.Handler.dispatchMessage + 102(Handler.java:102)
       at android.os.Looper.loop + 211(Looper.java:211)
       at android.app.ActivityThread.main + 5373(ActivityThread.java:5373)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke + 372(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 1020(ZygoteInit.java:1020)
       at com.android.internal.os.ZygoteInit.main + 815(ZygoteInit.java:815)

This crash is not happening for every user. I have tried asking users to update Chrome in the hope that it updates Chromium and also asking them to install the latest version of the Android System WebView but neither gave me any success. Has anyone come across this and know how to fix this? I can't even replicate it myself personally.

I also found this bug log here: https://bugs.chromium.org/p/chromium/issues/detail?id=925887

I've also looked at the source code and can see that the relevant crash is being caused by line 154: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/webkit/WebResourceResponse.java

The weird thing is that this supposedly should only happen when an error happens, but I can see that the WebView correctly loads for the user from screenshots and then the app crashes shortly after. Any help would be greatly appreciated!

like image 282
edwoollard Avatar asked Aug 08 '19 14:08

edwoollard


1 Answers

I also faced a similar issue when I used Jetpack webkit, from androidx.webkit package.

Using WebViewClientCompat from androidx.webkit for creating webViewClient resulted in the above exception, but falling back to framework's WebViewClient worked.

webview.webViewClient = WebViewClient()

like image 72
abitcode Avatar answered Oct 08 '22 08:10

abitcode