jdk/src/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java
changeset 10336 0bb1999251f8
parent 5506 202f599c92aa
--- a/jdk/src/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java	Mon Aug 15 12:56:01 2011 -0700
+++ b/jdk/src/share/classes/javax/crypto/EncryptedPrivateKeyInfo.java	Mon Aug 15 11:48:20 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2011, 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
@@ -80,7 +80,7 @@
             throw new NullPointerException("the encoded parameter " +
                                            "must be non-null");
         }
-        this.encoded = (byte[])encoded.clone();
+        this.encoded = encoded.clone();
         DerValue val = new DerValue(this.encoded);
 
         DerValue[] seq = new DerValue[2];
@@ -143,7 +143,7 @@
             throw new IllegalArgumentException("the encryptedData " +
                                                 "parameter must not be empty");
         } else {
-            this.encryptedData = (byte[])encryptedData.clone();
+            this.encryptedData = encryptedData.clone();
         }
         // delay the generation of ASN.1 encoding until
         // getEncoded() is called
@@ -183,7 +183,7 @@
             throw new IllegalArgumentException("the encryptedData " +
                                                 "parameter must not be empty");
         } else {
-            this.encryptedData = (byte[])encryptedData.clone();
+            this.encryptedData = encryptedData.clone();
         }
 
         // delay the generation of ASN.1 encoding until
@@ -222,7 +222,7 @@
      * each time this method is called.
      */
     public byte[] getEncryptedData() {
-        return (byte[])this.encryptedData.clone();
+        return this.encryptedData.clone();
     }
 
     /**
@@ -247,26 +247,13 @@
         throws InvalidKeySpecException {
         byte[] encoded = null;
         try {
-            encoded = cipher.doFinal((byte[])encryptedData);
+            encoded = cipher.doFinal(encryptedData);
             checkPKCS8Encoding(encoded);
-        } catch (GeneralSecurityException gse) {
-            InvalidKeySpecException ikse = new
-                InvalidKeySpecException(
-                    "Cannot retrieve the PKCS8EncodedKeySpec");
-            ikse.initCause(gse);
-            throw ikse;
-        } catch (IOException ioe) {
-            InvalidKeySpecException ikse = new
-                InvalidKeySpecException(
-                    "Cannot retrieve the PKCS8EncodedKeySpec");
-            ikse.initCause(ioe);
-            throw ikse;
-        } catch (IllegalStateException ise) {
-            InvalidKeySpecException ikse = new
-                InvalidKeySpecException(
-                    "Cannot retrieve the PKCS8EncodedKeySpec");
-            ikse.initCause(ise);
-            throw ikse;
+        } catch (GeneralSecurityException |
+                 IOException |
+                 IllegalStateException ex) {
+            throw new InvalidKeySpecException(
+                    "Cannot retrieve the PKCS8EncodedKeySpec", ex);
         }
         return new PKCS8EncodedKeySpec(encoded);
     }
@@ -289,16 +276,9 @@
         } catch (NoSuchAlgorithmException nsae) {
             // rethrow
             throw nsae;
-        } catch (GeneralSecurityException gse) {
-            InvalidKeyException ike = new InvalidKeyException
-                ("Cannot retrieve the PKCS8EncodedKeySpec");
-            ike.initCause(gse);
-            throw ike;
-        } catch (IOException ioe) {
-            InvalidKeyException ike = new InvalidKeyException
-                ("Cannot retrieve the PKCS8EncodedKeySpec");
-            ike.initCause(ioe);
-            throw ike;
+        } catch (GeneralSecurityException | IOException ex) {
+            throw new InvalidKeyException(
+                    "Cannot retrieve the PKCS8EncodedKeySpec", ex);
         }
         return new PKCS8EncodedKeySpec(encoded);
     }
@@ -413,7 +393,7 @@
             out.write(DerValue.tag_Sequence, tmp);
             this.encoded = out.toByteArray();
         }
-        return (byte[])this.encoded.clone();
+        return this.encoded.clone();
     }
 
     private static void checkTag(DerValue val, byte tag, String valName)
@@ -424,6 +404,7 @@
         }
     }
 
+    @SuppressWarnings("fallthrough")
     private static void checkPKCS8Encoding(byte[] encodedKey)
         throws IOException {
         DerInputStream in = new DerInputStream(encodedKey);
@@ -432,6 +413,7 @@
         switch (values.length) {
         case 4:
             checkTag(values[3], DerValue.TAG_CONTEXT, "attributes");
+            /* fall through */
         case 3:
             checkTag(values[0], DerValue.tag_Integer, "version");
             DerInputStream algid = values[1].toDerInputStream();