Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ public void onPermissionsDeny(String[] permissions, String permissionType, Strin

@Override
public void onShowSslCertificateErrorDialog(final WebView view, final SslErrorHandler handler, final SslError error) {
// Issue #1065: Activity may already be finishing/destroyed by the time the
// WebView delivers the SSL error callback on the main thread. Showing a
// dialog against a stale window token throws WindowManager$BadTokenException.
// Fail safe by cancelling the request when we cannot present UI.
if (mActivity == null || mActivity.isFinishing()
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())) {
handler.cancel();
return;
}
Comment on lines +374 to +378
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere in this class you copy this.mActivity into a local Activity mActivity before checking/using it (e.g., onLoading()), which avoids repeated field reads and makes the null/finishing/destroyed checks consistent. Here the method uses the field directly and later calls mActivity.isFinishing() again without a null check; consider adopting the same local-variable pattern (and include activity == null in the second guard) for consistency and to avoid potential NPEs if mActivity changes.

Copilot uses AI. Check for mistakes.
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mActivity);
String sslErrorMessage;
switch (error.getPrimaryError()) {
Expand Down Expand Up @@ -402,7 +411,18 @@ public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
alertDialog.show();
// Re-check just before show in case the activity transitioned during string lookup.
if (mActivity.isFinishing()
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())) {
handler.cancel();
return;
}
try {
alertDialog.show();
} catch (android.view.WindowManager.BadTokenException | IllegalStateException e) {
// Activity window went away between our check and show(); fail safe.
handler.cancel();
}


}
Expand Down
Loading