flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

fix: Prevent Android java.lang.NullPointerException in InAppWebViewCl…

Open kamilpowalowski opened this issue 2 years ago • 0 comments

…ient.onReceivedHttpAuthRequest view.getUrl()

Connection with issue(s)

Resolve issue Android Oreo 8.1 crash when an app uses HttpAuth.

Testing and Review Notes

I was able to reproduce it on Android Emulator with 8.1 and on some Soucelab devices (LG and Redmi, but not Samsung for example). After some tries, the web view manages to load. But then the device needs a restart and it will happen again. I wasn't able to replicate it on any other OS.

Screenshots or Videos

I have a crash log from a console.

W/System.err( 3845): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
W/System.err( 3845): 	at java.net.URI$Parser.parse(URI.java:3069)
W/System.err( 3845): 	at java.net.URI.<init>(URI.java:583)
W/System.err( 3845): 	at com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebViewClient.onReceivedHttpAuthRequest(InAppWebViewClient.java:334)
W/System.err( 3845): 	at com.android.webview.chromium.WebViewContentsClientAdapter.onReceivedHttpAuthRequest(WebViewContentsClientAdapter.java:420)
W/System.err( 3845): 	at org.chromium.android_webview.AwContents.onReceivedHttpAuthRequest(AwContents.java:690)
W/System.err( 3845): 	at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err( 3845): 	at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:7)
W/System.err( 3845): 	at android.os.Handler.dispatchMessage(Handler.java:106)
W/System.err( 3845): 	at android.os.Looper.loop(Looper.java:164)
W/System.err( 3845): 	at android.app.ActivityThread.main(ActivityThread.java:6494)
W/System.err( 3845): 	at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 3845): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
W/System.err( 3845): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Also, as documented https://developer.android.com/reference/android/webkit/WebView getUrl() can return null, but it wasn't checked in the code.

kamilpowalowski avatar Jun 28 '22 10:06 kamilpowalowski