diff --git a/CHANGELOG.md b/CHANGELOG.md index 4720259f..60316b14 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - Merged "Android fix leaking MethodChannel through anonymous class" [#1201](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1201) (thanks to [emakar](https://github.com/emakar)) - Merged "Fix RangeError: Maximum call stack size exceeded" [#1208](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1208) (thanks to [liasica](https://github.com/liasica)) - Merged "fix: try to open with Chrome if default browser app does not support custom tabs" [#1233](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1233) (thanks to [addie9000](https://github.com/addie9000)) +- Merged "fix: Prevent Android java.lang.NullPointerException in InAppWebViewCl…" [#1237](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1237) (thanks to [kamilpowalowski](https://github.com/kamilpowalowski)) ## 5.4.4+3 diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewClient.java index a2eca550..c7bd6bd2 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewClient.java @@ -343,22 +343,20 @@ public class InAppWebViewClient extends WebViewClient { @Override public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler, final String host, final String realm) { - URI uri; - try { - uri = new URI(view.getUrl()); - } catch (URISyntaxException e) { - e.printStackTrace(); + final String url = view.getUrl(); + String protocol = "https"; + int port = 0; - credentialsProposed = null; - previousAuthRequestFailureCount = 0; - - handler.cancel(); - return; + if (url != null) { + try { + URI uri = new URI(url); + protocol = uri.getScheme(); + port = uri.getPort(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } } - final String protocol = uri.getScheme(); - final int port = uri.getPort(); - previousAuthRequestFailureCount++; if (credentialsProposed == null) @@ -373,6 +371,8 @@ public class InAppWebViewClient extends WebViewClient { HttpAuthenticationChallenge challenge = new HttpAuthenticationChallenge(protectionSpace, previousAuthRequestFailureCount, credentialProposed); final InAppWebView webView = (InAppWebView) view; + final String finalProtocol = protocol; + final int finalPort = port; final WebViewChannelDelegate.ReceivedHttpAuthRequestCallback callback = new WebViewChannelDelegate.ReceivedHttpAuthRequestCallback() { @Override public boolean nonNullSuccess(@NonNull HttpAuthResponse response) { @@ -385,7 +385,7 @@ public class InAppWebViewClient extends WebViewClient { boolean permanentPersistence = response.isPermanentPersistence(); if (permanentPersistence) { CredentialDatabase.getInstance(view.getContext()) - .setHttpAuthCredential(host, protocol, realm, port, username, password); + .setHttpAuthCredential(host, finalProtocol, realm, finalPort, username, password); } handler.proceed(username, password); break; @@ -433,19 +433,20 @@ public class InAppWebViewClient extends WebViewClient { @Override public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError sslError) { - URI uri; + final String url = sslError.getUrl(); + String host = ""; + String protocol = "https"; + int port = 0; + try { - uri = new URI(sslError.getUrl()); + URI uri = new URI(url); + host = uri.getHost(); + protocol = uri.getScheme(); + port = uri.getPort(); } catch (URISyntaxException e) { e.printStackTrace(); - handler.cancel(); - return; } - final String host = uri.getHost(); - final String protocol = uri.getScheme(); - final int port = uri.getPort(); - URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, sslError.getCertificate(), sslError); ServerTrustChallenge challenge = new ServerTrustChallenge(protectionSpace); @@ -492,19 +493,20 @@ public class InAppWebViewClient extends WebViewClient { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onReceivedClientCertRequest(final WebView view, final ClientCertRequest request) { - URI uri; - try { - uri = new URI(view.getUrl()); - } catch (URISyntaxException e) { - e.printStackTrace(); - request.cancel(); - return; - } - + final String url = view.getUrl(); final String host = request.getHost(); - final String protocol = uri.getScheme(); + String protocol = "https"; final int port = request.getPort(); + if (url != null) { + try { + URI uri = new URI(url); + protocol = uri.getScheme(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + } + URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, view.getCertificate(), null); ClientCertChallenge challenge = new ClientCertChallenge(protectionSpace, request.getPrincipals(), request.getKeyTypes());