private boolean confirmAndUpdate(final X509Certificate[] chain, @NotNull CertificateConfirmationParameters parameters) {
    Application app = ApplicationManager.getApplication();
    final X509Certificate endPoint = chain[0];
    // IDEA-123467 and IDEA-123335 workaround
    String threadClassName = Strings.notNullize(Thread.currentThread().getClass().getCanonicalName());
    if (threadClassName.equals("sun.awt.image.ImageFetcher")) {
      LOG.debug("Image Fetcher thread is detected. Certificate check will be skipped.");
      return true;
    }

    if (app.isHeadlessEnvironment() || CertificateManager.getInstance().getState().ACCEPT_AUTOMATICALLY) {
      LOG.debug("Certificate will be accepted automatically");
      if (parameters.myAddToKeyStore) {
        myCustomManager.addCertificate(endPoint);
      }
      return true;
    }

    if (app.isUnitTestMode()) {
      return false;
    }

    boolean accepted = false;
    if (parameters.myAskUser) {

      String acceptLogMessage = "Going to ask user about certificate for: " + endPoint.getSubjectX500Principal().toString() +
                       ", issuer: " + endPoint.getIssuerX500Principal().toString();
      if (parameters.myAskOrRejectReason != null) {
        acceptLogMessage += ". Reason: " + parameters.myAskOrRejectReason;
      }
      LOG.info(acceptLogMessage);
      accepted = CertificateManager.Companion.showAcceptDialog(() -> {
        // TODO may be another kind of warning, if default trust store is missing
        return CertificateWarningDialog.createUntrustedCertificateWarning(endPoint, parameters.myCertificateDetails);
      });
    }
    else {
      String rejectLogMessage = "Didn't show certificate dialog for: " + endPoint.getSubjectX500Principal().toString() +
                       ", issuer: " + endPoint.getIssuerX500Principal().toString();
      if (parameters.myAskOrRejectReason != null) {
        rejectLogMessage += ". Reason: " + parameters.myAskOrRejectReason;
      }
      LOG.warn(rejectLogMessage);
    }
    if (accepted) {
      LOG.info("Certificate was accepted by user");
      if (parameters.myAddToKeyStore) {
        myCustomManager.addCertificate(endPoint);
      }
      if (parameters.myOnUserAcceptCallback != null) {
        parameters.myOnUserAcceptCallback.run();
      }
    }
    return accepted;
  }
private boolean confirmAndUpdate(final X509Certificate[] chain, @NotNull CertificateConfirmationParameters parameters)