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

KeyStore.load() fails to reinitialize (since 1.8.0_60)

XMLWordPrintable

    • b18
    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_92"
      Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
      Java HotSpot(TM) Client VM (build 25.92-b14, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [versão 10.0.10240]

      A DESCRIPTION OF THE PROBLEM :
      Before going into further detail please note that this issue describes the same unexpected behavior observed in JDK-8137256.
      For some unknown reason issue JDK-8137256 has been closed and marked as a duplicate of JDK-8136534, but the fact is that the problem described in JDK-8137256 persists.

      As for the problem description itself, 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_92, 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.

      Please note that you will also be able to reproduce this behavior in JREs builds 60, 65, 72 and 91.




      REGRESSION. Last worked in version 7u80

      ADDITIONAL REGRESSION INFORMATION:
      The precise release in which this issue is not present is "1.8.0_51".

      java version "1.8.0_51"
      Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, 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_51 you should get the following output:

      .\1.8.0_51\bin\java.exe KeystoreLoaderTestCase keystore.jks changeit
      #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_92 is the following:

      > .\1.8.0_92\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 :
      There is no workaround.

            snikandrova Svetlana Nikandrova (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: