harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r573500 - in /harmony/enhanced/classlib/trunk/modules/security/src: main/java/common/java/security/Provider.java test/api/java/org/apache/harmony/security/tests/java/security/Provider2Test.java
Date Fri, 07 Sep 2007 08:19:45 GMT
Author: leoli
Date: Fri Sep  7 01:19:44 2007
New Revision: 573500

URL: http://svn.apache.org/viewvc?rev=573500&view=rev
Log:
Fix bug in ([classlib][security]Provider.Service.getAliases leads to NPE in Secure.SecurityDorr.getAliases)

Modified:
    harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
    harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Provider2Test.java

Modified: harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java?rev=573500&r1=573499&r2=573500&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/main/java/common/java/security/Provider.java
Fri Sep  7 01:19:44 2007
@@ -806,6 +806,9 @@
         }
 
         Iterator<String> getAliases() {
+            if(aliases == null){
+                aliases = new ArrayList<String>(0);
+            }
             return aliases.iterator();
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Provider2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Provider2Test.java?rev=573500&r1=573499&r2=573500&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Provider2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/Provider2Test.java
Fri Sep  7 01:19:44 2007
@@ -17,7 +17,10 @@
 
 package org.apache.harmony.security.tests.java.security;
 
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.security.Provider;
+import java.security.Security;
 
 public class Provider2Test extends junit.framework.TestCase {
 
@@ -123,5 +126,45 @@
     public void test_toString() {
         // Regression for HARMONY-3734
         assertEquals("provTest version 1.2", provTest.toString());
+    }
+    
+    // Regression Test for Provider.Service.getAlias(), which is an package
+    // private method but will lead to NPE thrown at
+    // Secure.SecurityDorr.getAliases
+    public void test_getAlias() throws Exception {
+        MockProvider mockProvider = new MockProvider("MOCKNAME", 1.0,
+                "MOCKINFO");
+        Provider.Service service = new Provider.Service(mockProvider,
+                "MOCKTYPE", "MOCKALGORITHM", "TESTCLASSNAME", null, null);
+        mockProvider.putService(service);
+        Security.addProvider(mockProvider);
+        try {
+            MessageDigest messageDigest = MessageDigest
+                    .getInstance("NOTEXISTS");
+        }
+
+        catch (NoSuchAlgorithmException e) {
+            // expected
+        } finally {
+            Security.removeProvider("MOCKNAME");
+        }
+    }
+
+    public static class MockProvider extends Provider {
+
+        private static final long serialVersionUID = 1L;
+
+        public MockProvider(String name, double version, String info) {
+            super(name, version, info);
+
+        }
+
+        public void putService(Provider.Service service) {
+            super.putService(service);
+        }
+
+        public void removeService(Provider.Service service) {
+            super.removeService(service);
+        }
     }
 }



Mime
View raw message