Skip to content
Permalink
Browse files
8236671: NullPointerException in JKS keystore
Reviewed-by: hchao, xuelei
  • Loading branch information
coffeys committed Apr 30, 2021
1 parent e9370a1 commit 276a1bf7675e32784870f5559f6d3ac8bea07b6e
@@ -293,7 +293,7 @@ public void engineSetKeyEntry(String alias, Key key, char[] password,
}

} catch (Exception e) {
throw new KeyStoreException(e.getMessage());
throw new KeyStoreException(e.getMessage(), e);
}
}
}
@@ -281,6 +281,9 @@ public void engineSetKeyEntry(String alias, Key key, char[] password,
if (!(key instanceof java.security.PrivateKey)) {
throw new KeyStoreException("Cannot store non-PrivateKeys");
}
if (password == null) {
throw new KeyStoreException("password can't be null");
}
try {
synchronized(entries) {
KeyEntry entry = new KeyEntry();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,7 +40,7 @@

/*
* @test
* @bug 8048621 8133090 8167371
* @bug 8048621 8133090 8167371 8236671
* @summary Test basic operations with keystores (jks, jceks, pkcs12)
* @author Yu-Ching Valerie PENG
*/
@@ -163,6 +163,17 @@ public void runTest(String provider) throws Exception {
// create an empty key store
ks.load(null, null);

// unit test - test with null password
try {
ks.setKeyEntry(ALIAS_HEAD, privateKey, null,
new Certificate[] { cert });
} catch (KeyStoreException e) {
if (!e.getMessage().contains("password can\'t be null")) {
throw new RuntimeException("Unexpected message:" + e.getMessage());
}
// expected
}

// store the secret keys
for (int j = 0; j < numEntries; j++) {
ks.setKeyEntry(ALIAS_HEAD + j, privateKey, PASSWDK,

1 comment on commit 276a1bf

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 276a1bf Apr 30, 2021

Please sign in to comment.