]> granicus.if.org Git - icu/commitdiff
ICU-11976 test & fix ByteArrayWrapper.hashCode()
authorMarkus Scherer <markus.icu@gmail.com>
Fri, 30 Aug 2019 23:26:59 +0000 (16:26 -0700)
committerMarkus Scherer <markus.icu@gmail.com>
Wed, 4 Sep 2019 18:12:45 +0000 (11:12 -0700)
icu4j/main/classes/core/src/com/ibm/icu/util/ByteArrayWrapper.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/UtilityTest.java

index e39fdd07cfe12a1246ff22b8d6699af716168876..1c2c75c964eab46749ab14f3d088fa0dfaac144c 100644 (file)
@@ -237,7 +237,7 @@ public class ByteArrayWrapper implements Comparable<ByteArrayWrapper>
      */
     @Override
     public int hashCode() {
-        int result = bytes.length;
+        int result = size;
         for (int i = 0; i < size; ++i) {
             result = 37*result + bytes[i];
         }
index 7cfc9815e6c9e4e49337030dc447c92ab8b8a4e5..0613c2ddc4a1f862e7f2c74c79e2d78e4cc40cc8 100644 (file)
@@ -137,10 +137,10 @@ public class UtilityTest extends TestFmwk {
         }
 
         // test equality
-        if (!x.equals(y) || !x.equals(z))
-            errln("FAIL: test (operator ==): Failed!");
-        if (x.hashCode()!=y.hashCode())
-            errln("FAIL: identical objects have different hash codes.");
+        assertEquals("x==y", x, y);
+        assertEquals("y==z", y, z);
+        assertEquals("x.hashCode()==y.hashCode()", x.hashCode(), y.hashCode());
+        assertEquals("y.hashCode()==z.hashCode()", y.hashCode(), z.hashCode());
 
         // test non-equality
         y = new ByteArrayWrapper(bb, 4);