title: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
body: <p>I have added the certificate in Keystore, and I am trying to connect to the email exchange server using Java code. when I connect it throws a exception.</p>
  
  <p>The same thing works fine when I execute the same Java code in eclipse but fails when i execute the same with the service it fails.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public static void getEmailConnection(String folder){
  
  try{
  
      Store store = null;
      Properties properties = System.getProperties();
      Folder emailFolder = null;
  
      final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
      String host = "HOST NAME";
      String username = "username";// change accordingly
      String password = "password";// change accordingly
      String mailStoreType = "pop3";
      String port = "1234";
  
      //Set manual Properties
      properties.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
      properties.setProperty("mail.pop3.socketFactory.fallback", "false");
      properties.setProperty("mail.pop3.socketFactory.port", port);
      properties.setProperty("mail.store.protocol", mailStoreType);
      properties.setProperty("mail.pop3.host", host);
      properties.setProperty("mail.pop3.port", port);
  
  
      Session emailSession = Session.getDefaultInstance(properties);
      //create the POP3 store object and connect with the pop server
      store = emailSession.getStore("pop3");
      store.connect(host,1234,username, password);
  
      emailFolder = store.getFolder(folder);
      emailFolder.open(Folder.READ_ONLY);
  
  }catch(Exception e){
      throw new BsfConstraintViolationException("Unable to connect to Exchange Server",e);
      }
  }
  </code></pre>
  
  <p>please find the below stack trace.</p>
  
  <blockquote>
    <p>Caused by: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
        at sun.security.validator.PKIXValidator.(PKIXValidator.java:90)
        at sun.security.validator.Validator.getInstance(Validator.java:179)
        at sun.security.ssl.X509TrustManagerImpl.getValidator(X509TrustManagerImpl.java:314)
        at sun.security.ssl.X509TrustManagerImpl.checkTrustedInit(X509TrustManagerImpl.java:173)
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:186)
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:126)
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1320)
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:154)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1032)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1328)
        at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:882)
        at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
        ... 24 more</p>
  </blockquote>
  
  <p>Can any one please help me how to resolve this issue.</p>