8233016: javax.crypto.Cipher throws NPE for the given custom CipherSpi and Provider

Changed to throw IAE instead of NPE for non-null invalid arguments

Reviewed-by: mullan
This commit is contained in:
Valerie Peng 2019-12-05 03:55:52 +00:00
parent ab280fcac4
commit d4c0619b3b

View file

@ -264,15 +264,18 @@ public class Cipher {
* @param cipherSpi the delegate * @param cipherSpi the delegate
* @param provider the provider * @param provider the provider
* @param transformation the transformation * @param transformation the transformation
* @throws NullPointerException if {@code provider} is {@code null}
* @throws IllegalArgumentException if the supplied arguments
* are deemed invalid for constructing the Cipher object
*/ */
protected Cipher(CipherSpi cipherSpi, protected Cipher(CipherSpi cipherSpi,
Provider provider, Provider provider,
String transformation) { String transformation) {
// See bug 4341369 & 4334690 for more info. // See bug 4341369 & 4334690 for more info.
// If the caller is trusted, then okay. // If the caller is trusted, then okay.
// Otherwise throw a NullPointerException. // Otherwise throw an IllegalArgumentException.
if (!JceSecurityManager.INSTANCE.isCallerTrusted(provider)) { if (!JceSecurityManager.INSTANCE.isCallerTrusted(provider)) {
throw new NullPointerException(); throw new IllegalArgumentException("Cannot construct cipher");
} }
this.spi = cipherSpi; this.spi = cipherSpi;
this.provider = provider; this.provider = provider;