Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8328864

NullPointerException in sun.security.jca.ProviderList.getService()

XMLWordPrintable

    • b22
    • Verified

      Consider this trivial application code:


          import java.security.*;

          public class KeyStoreTest {

              public static void main(final String[] args) throws Exception {
                  final KeyStore ks = KeyStore.getInstance("PKCS12");
                  System.out.println("Got keystore " + ks);
              }
          }

      When compiled and run without any additional security properties as follows, it works fine:

          java KeyStoreTest
          Got keystore java.security.KeyStore@6b884d57

      Now create a file "/tmp/app-security.properties" file with the following contents (it sets a security property)

      jdk.security.provider.preferred=KeyStore.PKCS12:JipherJCE

      and run that program as follows by passing "/tmp/app-security.properties" to -Djava.security.properties:

          java -Djava.security.properties=/tmp/app-security.properties KeyStoreTest

      This time it throws a NullPointerException:

          Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.security.Provider.getService(String, String)" because "p" is null
              at java.base/sun.security.jca.ProviderList.getService(ProviderList.java:376)
              at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:157)
              at java.base/java.security.Security.getImpl(Security.java:658)
              at java.base/java.security.KeyStore.getInstance(KeyStore.java:870)
              at KeyStoreTest.main(KeyStoreTest.java:7)

      I ran this on Java 22 but is applicable for lower Java versions too.

            bperez Ben Perez
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: