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

KeyStore.load() fails to reinitialize in 1.8.0_60

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]
      Microsoft Windows [Version 6.2.9200]
      Microsoft Windows [Version 6.3.9600]


      A DESCRIPTION OF THE PROBLEM :
      According to the latest version of the KeyStore class reference documentation, once the keystore is loaded and the method load() is called multiple times it is supposed to reinitialize and load the contents of the given input stream.
      However, when using JRE 1.8.0_60, the load() method behaves differently. While the first call runs fine and the contents of the keystore are properly loaded, subsequent calls seem to fail.

      REGRESSION. Last worked in version 8u45

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      To reproduce this bug you need to compile and run the source code that is given.
      You will also need a dummy keystore holding at least one certificate entry.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Multiple calls to KeyStore.load() should always reinitialize and load the contents of a keystore.

      If you compile and run the source code given using JRE 1.8.0_45 you should get the following output:

      > .\1.8.0_45\bin\java KeystoreLoaderTestCase test-keystore.jks 1234
      #1 load() call got me 1 entries
      #2 load() call got me 1 entries

      ACTUAL -
      The actual output of running the source code given using JRE 1.8.0_60 is the following:

      > .\1.8.0_60\bin\java KeystoreLoaderTestCase test-keystore.jks 1234
      #1 load() call got me 1 entries
      #2 load() call got me 0 entries


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.FileInputStream;
      import java.io.InputStream;
      import java.security.KeyStore;

      public class KeystoreLoaderTestCase {

          public static void main(String[] args) {

              if (args.length != 2) {
                  return;
              }

              String keystore = args[0];
              String keystorePwd = args[1];
              try (InputStream is = new FileInputStream(keystore)) {
                  
                  KeyStore ks = KeyStore.getInstance("JKS");
                  ks.load(is, keystorePwd.toCharArray());
                  
                  System.out.println("#1 load() call got me " + ks.size() + " entries");

                  ks.load(null, keystorePwd.toCharArray());
                  System.out.println("#2 load() call got me " + ks.size() + " entries");
                  
              } catch (Exception ex) {
                  ex.printStackTrace();
              }

          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The only way of bypassing this bug is to avoid the #2 call to the load() method.

            vinnie Vincent Ryan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: