You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2009/10/07 11:59:11 UTC

svn commit: r822638 - in /harmony/enhanced/classlib/trunk/modules/crypto/src: main/java/javax/crypto/SealedObject.java test/api/java.injected/javax/crypto/SealedObjectTest.java

Author: hindessm
Date: Wed Oct  7 09:59:11 2009
New Revision: 822638

URL: http://svn.apache.org/viewvc?rev=822638&view=rev
Log:
Fix for SealedObject from "[#HARMONY-6347] crypto bugfixes" modified to
throw NPE rather than InvalidKeyException (to match RI behaviour) and
added regression test.

Modified:
    harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java
    harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/SealedObjectTest.java

Modified: harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java?rev=822638&r1=822637&r2=822638&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java (original)
+++ harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java Wed Oct  7 09:59:11 2009
@@ -155,6 +155,10 @@
     public final Object getObject(Key key)
                 throws IOException, ClassNotFoundException,
                        NoSuchAlgorithmException, InvalidKeyException {
+        if (key == null) {
+            throw new NullPointerException(
+                    Messages.getString("crypto.05"));
+        }
         try {
             Cipher cipher = Cipher.getInstance(sealAlg);
             if ((paramsAlg != null) && (paramsAlg.length() != 0)) {

Modified: harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/SealedObjectTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/SealedObjectTest.java?rev=822638&r1=822637&r2=822638&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/SealedObjectTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java.injected/javax/crypto/SealedObjectTest.java Wed Oct  7 09:59:11 2009
@@ -27,6 +27,7 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.security.Key;
+import java.security.InvalidKeyException;
 import java.util.Arrays;
 import javax.crypto.Cipher;
 import javax.crypto.KeyGenerator;
@@ -221,5 +222,15 @@
                 + "original object.", secret, so.getObject(key, provider));
     }
 
+    // Regression test for HARMONY-6347
+    public void testGetObject4() throws Exception {
+        try {
+            new SealedObject("secret string",
+                             new NullCipher()).getObject((Key)null);
+            fail("NullPointerException should be thrown when key is null");
+        } catch (NullPointerException e) {
+        }
+    }
+
 }