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,14 @@ public void onPermissionsDeny(String[] permissions, String permissionType, Strin

@Override
public void onShowSslCertificateErrorDialog(final WebView view, final SslErrorHandler handler, final SslError error) {
Activity mActivity;
if ((mActivity = this.mActivity) == null || mActivity.isFinishing()) {
// Issue #1065: Avoid BadTokenException when the host activity has
// already started finishing. Mirror the guard used by every other
// dialog method in this class (onLoading, onCancelLoading, ...).
Comment on lines +371 to +374
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

The new guard only checks isFinishing(), but other dialog methods in this class also guard against Activity.isDestroyed() (API >= 17). Without the isDestroyed() check, this method can still attempt to show a dialog during/after destruction (e.g., configuration change), which can still throw BadTokenException. Consider adding the same Build.VERSION.SDK_INT / isDestroyed() early-return here (and cancel the SslErrorHandler in that path as well).

Suggested change
if ((mActivity = this.mActivity) == null || mActivity.isFinishing()) {
// Issue #1065: Avoid BadTokenException when the host activity has
// already started finishing. Mirror the guard used by every other
// dialog method in this class (onLoading, onCancelLoading, ...).
if ((mActivity = this.mActivity) == null
|| mActivity.isFinishing()
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())) {
// Avoid BadTokenException when the host activity is not in a valid
// state to show dialogs, including the destroyed state on API 17+.

Copilot uses AI. Check for mistakes.
handler.cancel();
return;
}
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mActivity);
String sslErrorMessage;
switch (error.getPrimaryError()) {
Expand Down
Loading