harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r453152 - in /incubator/harmony/enhanced/classlib/trunk/modules/crypto/src: main/java/javax/crypto/Cipher.java test/api/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java
Date Thu, 05 Oct 2006 09:07:58 GMT
Author: mloenko
Date: Thu Oct  5 02:07:57 2006
New Revision: 453152

URL: http://svn.apache.org/viewvc?view=rev&rev=453152
Log:
applied newest patches for HARMONY-1184
[classlib][crypto] compatibility: Cipher(null, null, "s") lead to NPE on RI and works silently
on Harmony

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java?view=diff&rev=453152&r1=453151&r2=453152
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/Cipher.java
Thu Oct  5 02:07:57 2006
@@ -40,10 +40,10 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
+import org.apache.harmony.crypto.internal.NullCipherSpi;
 import org.apache.harmony.crypto.internal.nls.Messages;
 import org.apache.harmony.security.fortress.Engine;
 
-
 /**
  * @com.intel.drl.spec_ref
  * 
@@ -127,6 +127,12 @@
      */
     protected Cipher(CipherSpi cipherSpi, Provider provider,
             String transformation) {
+        if (cipherSpi == null) {
+            throw new NullPointerException();
+        }
+        if (!(cipherSpi instanceof NullCipherSpi) && provider == null) {
+            throw new NullPointerException();
+        }
         this.provider = provider;
         this.transformation = transformation;
         this.spiImpl = cipherSpi;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java?view=diff&rev=453152&r1=453151&r2=453152
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/CipherTest.java
Thu Oct  5 02:07:57 2006
@@ -31,6 +31,7 @@
 import java.util.Arrays;
 
 import javax.crypto.Cipher;
+import javax.crypto.CipherSpi;
 import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKeyFactory;
 import javax.crypto.ShortBufferException;
@@ -38,6 +39,7 @@
 import javax.crypto.spec.IvParameterSpec;
 
 import tests.support.resource.Support_Resources;
+import org.apache.harmony.crypto.tests.support.MyCipher;
 
 public class CipherTest extends junit.framework.TestCase {
 
@@ -435,5 +437,38 @@
         } catch (NoSuchAlgorithmException e) {
         }
     }
-    
+
+    /**
+     * @tests javax.crypto.Cipher#Cipher(CipherSpi cipherSpi, Provider provider,
+     *        String transformation)
+     */
+    public void test_Ctor() throws Exception {
+        // Regression for Harmony-1184
+        try {
+            new testCipher(null, null, "s");
+            fail("NullPointerException expected");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            new testCipher(new MyCipher(), null, "s");
+            fail("NullPointerException expected for 'null' provider");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            new testCipher(null, new Provider("qwerty", 1.0, "qwerty") {}, "s");
+            fail("NullPointerException expected for 'null' cipherSpi");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    class testCipher extends Cipher {
+        testCipher(CipherSpi c, Provider p, String s) {
+            super(c, p, s);
+        }
+    }
 }



Mime
View raw message