@Override
  public X509Certificate[] getAcceptedIssuers() {
    X509Certificate[] issuers = EMPTY;
    X509TrustManager tm = trustManagerRef.get();
    if (tm != null) {
      issuers = tm.getAcceptedIssuers();
    }
    return issuers;
  }
@Test (timeout = 30000)
  public void testReloadCorruptTrustStore() throws Exception {
    KeyPair kp = generateKeyPair("RSA");
    cert1 = generateCertificate("CN=Cert1", kp, 30, "SHA1withRSA");
    cert2 = generateCertificate("CN=Cert2", kp, 30, "SHA1withRSA");
    String truststoreLocation = BASEDIR + "/testcorrupt.jks";
    createTrustStore(truststoreLocation, "password", "cert1", cert1);

    long reloadInterval = 10;
    Timer fileMonitoringTimer = new Timer(FileBasedKeyStoresFactory.SSL_MONITORING_THREAD_NAME, true);
    ReloadingX509TrustManager tm =
      new ReloadingX509TrustManager("jks", truststoreLocation, "password");
    try {
      fileMonitoringTimer.schedule(new FileMonitoringTimerTask(
              Paths.get(truststoreLocation), tm::loadFrom,null), reloadInterval, reloadInterval);
      assertEquals(1, tm.getAcceptedIssuers().length);
      final X509Certificate cert = tm.getAcceptedIssuers()[0];

      // Wait so that the file modification time is different
      Thread.sleep((reloadInterval + 1000));

      assertFalse(reloaderLog.getOutput().contains(
              FileMonitoringTimerTask.PROCESS_ERROR_MESSAGE));
      OutputStream os = new FileOutputStream(truststoreLocation);
      os.write(1);
      os.close();

      waitForFailedReloadAtLeastOnce((int) reloadInterval);

      assertEquals(1, tm.getAcceptedIssuers().length);
      assertEquals(cert, tm.getAcceptedIssuers()[0]);
    } finally {
      reloaderLog.stopCapturing();
      fileMonitoringTimer.cancel();
    }
  }