Skip to content

Commit

Permalink
Fixing ArrayMap hashCode to work with null values
Browse files Browse the repository at this point in the history
  • Loading branch information
KotaiVictor authored and mattwhisenhunt committed Dec 11, 2017
1 parent 9578ae8 commit d2d73b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ public V setValue(V value) {

@Override
public int hashCode() {
return getKey().hashCode() ^ getValue().hashCode();
K key = getKey();
V value = getValue();
return (key != null ? key.hashCode() : 0) ^ (value != null ? value.hashCode() : 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ public void testSet() {
} catch (IndexOutOfBoundsException e) {
}
}

public void testHashCode() {
ArrayMap<String, Integer> map = ArrayMap.of();
map.set(0, "a", null);
map.set(1, null, 1);
map.set(2, null, null);

assertTrue(map.hashCode() > 0);
}
}

0 comments on commit d2d73b1

Please sign in to comment.