JDK-8137256 : KeyStore.load() fails to reinitialize in 1.8.0_60
  • Type: Bug
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 8u60,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_8
  • CPU: x86
  • Submitted: 2015-09-25
  • Updated: 2015-10-14
  • Resolved: 2015-10-14
Related Reports
Duplicate :  
Description
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.


Comments
Attached Test case was executed on Windows 7 with : JDK 8u45 - Pass JDK 8u51 - Pass JDK 8u60 - Fail JDK 8u66 - Fail JDK 9ea - Fail Moving to dev-team for evaluation.
28-09-2015