harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r420696 - in /incubator/harmony/enhanced/classlib/trunk/modules/crypto/src: main/java/javax/crypto/ExemptionMechanism.java test/api/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java
Date Tue, 11 Jul 2006 03:48:48 GMT
Author: mloenko
Date: Mon Jul 10 20:48:47 2006
New Revision: 420696

URL: http://svn.apache.org/viewvc?rev=420696&view=rev
Log:
fixes for HARMONY-762
[classlib][security]compatibility: exception order javax.crypto.ExemptionMechanism.getInstance(null,Provider)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/ExemptionMechanism.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/ExemptionMechanism.java?rev=420696&r1=420695&r2=420696&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/ExemptionMechanism.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/ExemptionMechanism.java
Mon Jul 10 20:48:47 2006
@@ -107,15 +107,15 @@
     public static final ExemptionMechanism getInstance(String algorithm,
             String provider) throws NoSuchAlgorithmException,
             NoSuchProviderException {
-        if (algorithm == null) {
-            throw new NullPointerException("Algorithm is null");
-        }
         if (provider == null) {
             throw new IllegalArgumentException("Provider is null");
         }
         Provider impProvider = Security.getProvider(provider);
         if (impProvider == null) {
             throw new NoSuchProviderException(provider);
+        }
+        if (algorithm == null) {
+            throw new NullPointerException("Algorithm is null");
         }
         return getInstance(algorithm, impProvider);
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.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/ExemptionMechanismTest.java?rev=420696&r1=420695&r2=420696&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/ExemptionMechanismTest.java
Mon Jul 10 20:48:47 2006
@@ -22,89 +22,80 @@
 package org.apache.harmony.crypto.tests.javax.crypto;
 
 import java.security.InvalidKeyException;
+import java.security.NoSuchProviderException;
 import java.security.Provider;
 
 import javax.crypto.ExemptionMechanism;
 import javax.crypto.ExemptionMechanismSpi;
 
+import junit.framework.TestCase;
+
 import org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi;
 import org.apache.harmony.security.tests.support.SpiEngUtils;
-import org.apache.harmony.security.tests.support.SpiEngUtils.MyProvider;
 
-import junit.framework.TestCase;
 /**
  * Tests for <code>ExemptionMechanism</code> class constructors and methods
  * 
  */
 
 public class ExemptionMechanismTest extends TestCase {
-    
-    public static final String srvExemptionMechanism = "ExemptionMechanism";
-    
+
+    private static final String srvExemptionMechanism = "ExemptionMechanism";
+
     private static final String defaultAlg = "EMech";
-    
+
     private static final String ExemptionMechanismProviderClass = "org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi";
 
     /**
-     * Constructor for SecurityManagerFactoryTest2.
-     * 
-     * @param arg0
-     */
-    public ExemptionMechanismTest(String arg0) {
-        super(arg0);
-    }
-   
-    /**
      * Test for <code>ExemptionMechanism</code> constructor 
      * Assertion: cretes new object using provider and mechanism name
      */
     public void testExemptionMechanism() throws Exception {
-        Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider
for ExemptionMechanism testing", 
-                srvExemptionMechanism.concat(".").concat(defaultAlg), 
+        Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider",
+                "Provider for ExemptionMechanism testing",
+                srvExemptionMechanism.concat(".").concat(defaultAlg),
                 ExemptionMechanismProviderClass);
-        
+
         ExemptionMechanismSpi spi = new MyExemptionMechanismSpi();
-        ExemptionMechanism em = new MyMechanism(spi, mProv, defaultAlg);
-        
+
+        ExemptionMechanism em = new ExemptionMechanism(spi, mProv, defaultAlg) {};
         assertEquals("Incorrect provider", em.getProvider(), mProv);
         assertEquals("Incorrect algorithm", em.getName(), defaultAlg);
         try {
             em.init(null);
             fail("InvalidKeyException must be thrown");
-        } catch (InvalidKeyException e) {
-        }
+        } catch (InvalidKeyException e) {}
+
         try {
             em.getOutputSize(100);
             fail("IllegalStateException must be thrown");
-        } catch (IllegalStateException e) {
-        }        
-        em = new MyMechanism(null, null, null);
+        } catch (IllegalStateException e) {}
+
+
+        em = new ExemptionMechanism(null, null, null) {};
         assertNull("Incorrect mechanism", em.getName());
         assertNull("Incorrect provider", em.getProvider());
         try {
             em.init(null);
             fail("NullPointerException must be thrown");
-        } catch (NullPointerException e) {
-        }
+        } catch (NullPointerException e) {}
         try {
             em.getOutputSize(100);
             fail("IllegalStateException must be thrown");
-        } catch (IllegalStateException e) {
-        }        
+        } catch (IllegalStateException e) {}
     }
-}
-
-class MyMechanism extends ExemptionMechanism {
 
-    public MyMechanism(ExemptionMechanismSpi spi, Provider prov, String mechanism) {
-        super(spi, prov, mechanism);
-    }
-
-    public void finalize() {
+    /**
+     * @tests javax/crypto/ExemptionMechanism#getInstance(String algorithm, String provider)
+     * Checks exception order
+     */
+    public void testGetInstance() throws Exception {
+        //Regression for HARMONY-762
         try {
-            super.finalize();
-        } catch (Throwable e) {
-            throw new RuntimeException("finalize was broken", e);
+            ExemptionMechanism.getInstance((String) null, "aaa");
+            fail("NoSuchProviderException must be thrown");
+        } catch (NoSuchProviderException pe) {
+            //expected
         }
     }
 }



Mime
View raw message