Revision: 7168
Author: [email protected]
Date: Tue Nov 24 15:26:15 2009
Log: Fix Arrays.equals(Object[], Object[]) to handle nulls, this time  
correctly.

Patch by: [email protected]
Review by: jat

http://code.google.com/p/google-web-toolkit/source/detail?r=7168

Modified:
  /trunk/user/super/com/google/gwt/emul/java/util/Arrays.java
  /trunk/user/test/com/google/gwt/emultest/java/util/ArraysTest.java

=======================================
--- /trunk/user/super/com/google/gwt/emul/java/util/Arrays.java Mon Nov 23  
12:40:55 2009
+++ /trunk/user/super/com/google/gwt/emul/java/util/Arrays.java Tue Nov 24  
15:26:15 2009
@@ -680,7 +680,7 @@
      for (int i = 0; i < array1.length; ++i) {
        Object val1 = array1[i];
        Object val2 = array2[i];
-      if (!val1.equals(val2)) {
+      if (!Utility.equalsWithNullCheck(val1, val2)) {
          return false;
        }
      }
=======================================
--- /trunk/user/test/com/google/gwt/emultest/java/util/ArraysTest.java  Mon  
Nov 23 12:40:55 2009
+++ /trunk/user/test/com/google/gwt/emultest/java/util/ArraysTest.java  Tue  
Nov 24 15:26:15 2009
@@ -70,6 +70,40 @@
      String[] a = new String[] { "foo", null, "bar", "baz" };
      Arrays.hashCode(a);
    }
+
+  public void testArraysEqualsWithEmptyArrays() {
+    assertTrue(Arrays.equals(new String[0], new String[0]));
+  }
+
+  public void testArraysEqualsWithoutNullElementsEqual() {
+    assertTrue(Arrays.equals(
+        new String[] { "foo" }, new String[]{ "foo" }));
+  }
+
+  public void testArraysEqualsWithoutNullElementsNotEqual() {
+    assertFalse(Arrays.equals(
+        new String[] { "foo" }, new String[]{ "bar" }));
+  }
+
+  public void testArraysEqualsWithNullElementsEqual() {
+    assertTrue(Arrays.equals(new String[2], new String[2]));
+  }
+
+  public void testArraysEqualsWithNullElementsNotEqual() {
+    assertFalse(Arrays.equals(new String[2], new String[1]));
+  }
+
+  public void testArraysEqualsWithNullAndNonNullElementsEqual() {
+    assertTrue(Arrays.equals(
+        new String[]{ null, "foo", null, "bar" },
+        new String[]{ null, "foo", null, "bar" }));
+  }
+
+  public void testArraysEqualsWithNullAndNonNullElementsNotEqual() {
+    assertFalse(Arrays.equals(
+        new String[]{ null, "bar", null, "foo" },
+        new String[]{ null, "foo", null, "foo" }));
+  }

    /**
     * Tests {...@link Arrays#asList(Object[])}.
@@ -606,7 +640,7 @@
     * Advance the permutation to the next value. It leaves the first index  
set to
     * -1 if the range has been exceeded.
     *
-   * @param permutation array of indices -- see {...@link getPermutation} for
+   * @param permutation array of indices -- see {...@link #getPermutation} for
     *          details.
     */
    private void nextPermutation(int[] permutation) {
@@ -621,7 +655,7 @@

    /**
     * Checks to see if this permutation is valid; ie, if all of the indices  
are
-   * between 0 and n-i (see {...@link getPermutation} for details).
+   * between 0 and n-i (see {...@link #getPermutation} for details).
     *
     * @param permutations array of indices
     * @param n length of source array.

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to