changeset 57239:832efc785f53

8233016: javax.crypto.Cipher throws NPE for the given custom CipherSpi and Provider Summary: Changed to throw IAE instead of NPE for non-null invalid arguments Reviewed-by: mullan
author valeriep
date Thu, 05 Dec 2019 03:55:52 +0000
parents 18420160287b
children e4b6321c11a4
files src/java.base/share/classes/javax/crypto/Cipher.java
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/javax/crypto/Cipher.java	Thu Dec 05 10:36:46 2019 +0800
+++ b/src/java.base/share/classes/javax/crypto/Cipher.java	Thu Dec 05 03:55:52 2019 +0000
@@ -264,15 +264,18 @@
      * @param cipherSpi the delegate
      * @param provider the provider
      * @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,
                      Provider provider,
                      String transformation) {
         // See bug 4341369 & 4334690 for more info.
         // If the caller is trusted, then okay.
-        // Otherwise throw a NullPointerException.
+        // Otherwise throw an IllegalArgumentException.
         if (!JceSecurityManager.INSTANCE.isCallerTrusted(provider)) {
-            throw new NullPointerException();
+            throw new IllegalArgumentException("Cannot construct cipher");
         }
         this.spi = cipherSpi;
         this.provider = provider;