8000 JAVA-942: Incorrect implementation of UserType.hashCode() by adutra · Pull Request #475 · apache/cassandra-java-driver · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### 2.2.0-rc4 (in progress)

- [bug] Incorrect implementation of UserType.hashCode() (JAVA-942)

Merged from 2.0 branch:

- [improvement] Log streamid at the trace level on sending request and receiving response (JAVA-718)
Expand Down
11 changes: 8 additions & 3 deletions driver-core/src/main/java/com/datastax/driver/core/UserType.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ public boolean isFrozen() {
}

@Override
public final int hashCode() {
return Arrays.hashCode(new Object[]{ name, keyspace, typeName, byIdx });
public int hashCode() {
int result = name.hashCode();
result = 31 * result + keyspace.hashCode();
result = 31 * result + typeName.hashCode();
result = 31 * result + Arrays.hashCode(byIdx);
return result;
}

@Override
Expand All @@ -183,7 +187,8 @@ public final boolean equals(Object o) {

// Note: we don't test byName because it's redundant with byIdx in practice,
// but also because the map holds 'int[]' which don't have proper equal.
return keyspace.equals(other.keyspace)
return name.equals(other.name)
&& keyspace.equals(other.keyspace)
&& typeName.equals(other.typeName)
&& Arrays.equals(byIdx, other.byIdx);
}
Expand Down
0