Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 13, 2022
Merged

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

merged 2 commits into from
Oct 13, 2022

Conversation

kamilpowalowski
Copy link
Contributor

@kamilpowalowski kamilpowalowski commented Jun 28, 2022

…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 and others added 2 commits October 5, 2022 10:11
…ient.onReceivedHttpAuthRequest view.getUrl()
Added more checks when trying to parse an URL using URI and allow the request to go to the flutter delegate.
@pichillilorenzo pichillilorenzo merged commit 8889b0d into pichillilorenzo:master Oct 13, 2022
@pichillilorenzo
Copy link
Owner

Thanks! @all-contributors please add @kamilpowalowski for code

@allcontributors
Copy link
Contributor

@pichillilorenzo

I've put up a pull request to add @kamilpowalowski! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants