diff --git a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java index dad534767..c64928cfd 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java @@ -153,9 +153,17 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList afe.getMessage() == null ? "" : afe.getMessage()); } catch (final CertificateValidationException cve) { Log.e(K9.LOG_TAG, "Error while testing settings", cve); - acceptKeyDialog( - R.string.account_setup_failed_dlg_certificate_message_fmt, - cve); + + // Avoid NullPointerException in acceptKeyDialog() + if (TrustManagerFactory.getLastCertChain() != null) { + acceptKeyDialog( + R.string.account_setup_failed_dlg_certificate_message_fmt, + cve); + } else { + showErrorDialog( + R.string.account_setup_failed_dlg_server_message_fmt, + (cve.getMessage() == null ? "" : cve.getMessage())); + } } catch (final Throwable t) { Log.e(K9.LOG_TAG, "Error while testing settings", t); showErrorDialog( diff --git a/src/com/fsck/k9/mail/store/TrustManagerFactory.java b/src/com/fsck/k9/mail/store/TrustManagerFactory.java index b6ead8d9d..32c9f4572 100644 --- a/src/com/fsck/k9/mail/store/TrustManagerFactory.java +++ b/src/com/fsck/k9/mail/store/TrustManagerFactory.java @@ -76,6 +76,8 @@ public final class TrustManagerFactory { public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + // FIXME: Using a static field to store the certificate chain is a bad idea. Instead + // create a CertificateException subclass and store the chain there. TrustManagerFactory.setLastCertChain(chain); try { defaultTrustManager.checkServerTrusted(chain, authType);