title: InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
body: <p>I am getting this weird error from my java code:</p>
  
  <pre><code>java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
  </code></pre>
  
  <p>The command I used to generate the keystore:
  <code>keytool -genkey -alias tomcat -keystore keystore.jks</code></p>
  
  <p>Here is my java code:</p>
  
  <pre><code>import java.security.cert.PKIXParameters;
  import java.security.KeyStore;
  import java.io.FileInputStream;
  
  public class MyKeyTest {
      public static void main(String[] args) throws Exception {
          KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
          String password = "mypass";
          ks.load(new FileInputStream("keystore.jks"), password.toCharArray());
          new PKIXParameters(ks);
      }
  }
  </code></pre>
  
  <p>I tried to google around for this error but mostly it says this happens when keystore was not found or is not permissive to be read.</p>
  
  <p>But neither of these two cases is true in my case. Any ideas?</p>