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

(spec) confusing exception list for javax.crypto.Cipher.init(...)

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 20
    • security-libs
    • None
    • behavioral
    • minimal
    • JavaDoc updates for Cipher.init methods to document existing exceptional behavior.
    • Java API
    • SE

    Description

      Summary

      The Cipher init methods do not list an InvalidParameterException as being thrown in their javadocs, though this is possible if the opmode is not a valid value.

      Problem

      See Summary (above).

      Solution

      The javadoc was updated to include InvalidParameterException as being thrown for all Cipher.init methods

      Specification

      diff --git a/src/java.base/share/classes/javax/crypto/Cipher.java b/src/java.base/share/classes/javax/crypto/Cipher.java
      index 5d2f37d63127..2eb2ffe14a4a 100644
      --- a/src/java.base/share/classes/javax/crypto/Cipher.java
      +++ b/src/java.base/share/classes/javax/crypto/Cipher.java
      @@ -1239,6 +1239,8 @@ private static void checkOpmode(int opmode) {
            * @throws UnsupportedOperationException if {@code opmode} is
            * {@code WRAP_MODE} or {@code UNWRAP_MODE} but the mode is not implemented
            * by the underlying {@code CipherSpi}
      +     * @throws InvalidParameterException if {@code opmode} is not one of the
      +     * recognized values
            */
           public final void init(int opmode, Key key) throws InvalidKeyException {
               init(opmode, key, JCAUtil.getDefSecureRandom());
      @@ -1294,6 +1296,8 @@ public final void init(int opmode, Key key) throws InvalidKeyException {
            * @throws UnsupportedOperationException if {@code opmode} is
            * {@code WRAP_MODE} or {@code UNWRAP_MODE} but the mode is not implemented
            * by the underlying {@code CipherSpi}
      +     * @throws InvalidParameterException if {@code opmode} is not one of the
      +     * recognized values
            */
           public final void init(int opmode, Key key, SecureRandom random)
                   throws InvalidKeyException
      @@ -1379,6 +1383,9 @@ public final void init(int opmode, Key key, SecureRandom random)
            * @throws UnsupportedOperationException if {@code opmode} is
            * {@code WRAP_MODE} or {@code UNWRAP_MODE} but the mode is not implemented
            * by the underlying {@code CipherSpi}
      +     * @throws InvalidParameterException if {@code opmode} is not one of the
      +     * recognized values
      +     *
            */
           public final void init(int opmode, Key key, AlgorithmParameterSpec params)
                   throws InvalidKeyException, InvalidAlgorithmParameterException
      @@ -1441,6 +1448,9 @@ public final void init(int opmode, Key key, AlgorithmParameterSpec params)
            * @throws UnsupportedOperationException if {@code opmode} is
            * {@code WRAP_MODE} or {@code UNWRAP_MODE} but the mode is not implemented
            * by the underlying {@code CipherSpi}
      +     * @throws InvalidParameterException if {@code opmode} is not one of the
      +     * recognized values
      +     *
            */
           public final void init(int opmode, Key key, AlgorithmParameterSpec params,
                                  SecureRandom random)
      @@ -1522,6 +1532,8 @@ public final void init(int opmode, Key key, AlgorithmParameterSpec params,
            * @throws UnsupportedOperationException if {@code opmode} is
            * {@code WRAP_MODE} or {@code UNWRAP_MODE} but the mode is not implemented
            * by the underlying {@code CipherSpi}
      +     * @throws InvalidParameterException if {@code opmode} is not one of the
      +     * recognized values
            */
           public final void init(int opmode, Key key, AlgorithmParameters params)
                   throws InvalidKeyException, InvalidAlgorithmParameterException
      @@ -1584,6 +1596,8 @@ public final void init(int opmode, Key key, AlgorithmParameters params)
            * @throws UnsupportedOperationException if {@code opmode} is
            * {@code WRAP_MODE} or {@code UNWRAP_MODE} but the mode is not implemented
            * by the underlying {@code CipherSpi}
      +     * @throws InvalidParameterException if {@code opmode} is not one of the
      +     * recognized values
            */
           public final void init(int opmode, Key key, AlgorithmParameters params,
                                  SecureRandom random)
      @@ -1671,6 +1685,8 @@ public final void init(int opmode, Key key, AlgorithmParameters params,
            * @throws UnsupportedOperationException if {@code opmode} is
            * {@code WRAP_MODE} or {@code UNWRAP_MODE} but the mode is not implemented
            * by the underlying {@code CipherSpi}
      +     * @throws InvalidParameterException if {@code opmode} is not one of the
      +     * recognized values
            */
           public final void init(int opmode, Certificate certificate)
                   throws InvalidKeyException
      @@ -1740,6 +1756,8 @@ public final void init(int opmode, Certificate certificate)
            * @throws UnsupportedOperationException if {@code opmode} is
            * {@code WRAP_MODE} or {@code UNWRAP_MODE} but the mode is not implemented
            * by the underlying {@code CipherSpi}
      +     * @throws InvalidParameterException if {@code opmode} is not one of the
      +     * recognized values
            */
           public final void init(int opmode, Certificate certificate,
                                  SecureRandom random)
      

      Attachments

        Issue Links

          Activity

            People

              kdriver Kevin Driver
              duke J. Duke
              Valerie Peng
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: