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

svn commit: r556844 - in /harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/javax/naming/ldap/SortControl.java test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java

Author: pyang
Date: Tue Jul 17 01:11:42 2007
New Revision: 556844

URL: http://svn.apache.org/viewvc?view=rev&rev=556844
Log:
SortControl's constructor doesn't handle the array parameter properly when that array contains null elements. Further, the non-ascii characters in the SortKey are not encoded property.

Modified:
    harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java
    harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java?view=diff&rev=556844&r1=556843&r2=556844
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java Tue Jul 17 01:11:42 2007
@@ -18,6 +18,7 @@
 package javax.naming.ldap;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 
 import org.apache.harmony.security.asn1.ASN1Boolean;
@@ -61,7 +62,12 @@
         public void getValues(Object object, Object values[]) {
             SortKey sk = (SortKey) object;
 
-            values[0] = sk.getAttributeID().getBytes();
+            try {
+                values[0] = sk.getAttributeID().getBytes("utf-8");
+            } catch (UnsupportedEncodingException e) {
+                //FIXME: is this right thing to do?
+                values[0] = sk.getAttributeID().getBytes();
+            }
             values[1] = sk.getMatchingRuleID();
             values[2] = Boolean.valueOf(!sk.isAscending());
         }
@@ -93,7 +99,11 @@
         super(OID, criticality, null);
         ArrayList<SortKey> list = new ArrayList<SortKey>();
         for (int i = 0; i < sortBy.length; i++) {
-            list.add(new SortKey(sortBy[i], true, null));
+            if(sortBy[i] != null){
+                list.add(new SortKey(sortBy[i], true, null));
+            }else{
+                list.add(new SortKey("", true, null));
+            }
         }
         value = ASN1_SORTKEYLIST.encode(list);
     }

Modified: harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java?view=diff&rev=556844&r1=556843&r2=556844
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java Tue Jul 17 01:11:42 2007
@@ -84,6 +84,32 @@
         assertEquals("30 10 30 0e 04 04 70 65 70 65 80 03 6c 65 6f 81 01 ff",
                 toHexString(sc.getEncodedValue()));
     }
+    
+    public void testEncodedValueOfSortControlNull() throws Exception{
+        String[] sk = {"pepe", null, "", "haha" };
+
+        SortControl sc = new SortControl(sk, true);
+        assertEquals("30 18 30 06 04 04 70 65 70 65 30 02 04 00 30 02 04 00 30 06 04 04 68 61 68 61",
+                toHexString(sc.getEncodedValue()));
+        
+        String[] sk2 = {"pepe", "", "haha" };
+        sc = new SortControl(sk2, true);
+        assertEquals("30 14 30 06 04 04 70 65 70 65 30 02 04 00 30 06 04 04 68 61 68 61",
+                toHexString(sc.getEncodedValue()));
+        
+        SortKey[] sk3 = {new SortKey("pepe", false, "haha"), null, new SortKey("", true, "haha2"), new SortKey("haah", true, "pepe")};
+        try{
+            sc = new SortControl(sk3, true);
+            fail("should throw NPE");
+        }catch(NullPointerException e){
+        }
+        
+        SortKey[] sk4 = {new SortKey("pepe", false, "haha"), new SortKey("", true, "haha2"), new SortKey("haah", true, "pepe")};
+        sc = new SortControl(sk4, true);
+        assertEquals("30 2a 30 0f 04 04 70 65 70 65 80 04 68 61 68 61 81 01 ff 30 09 04 00 80 05 68 61 68 61 32 30 0c 04 04 68 61 61 68 80 04 70 65 70 65",
+                toHexString(sc.getEncodedValue()));
+
+    }
 
     /**
      * <p>