mirror of https://github.com/facebook/rocksdb.git
Fix Java hashCode implementation (#7860)
Summary: Classes ColumnFamilyHandle and CapturingWriteBatchHandler.Event have byte array fields as part of their identity, but they do not use the arrays' content to compute the instance's hash, and instead rely on the arrays' identity, causing instances to have different hashcodes although they are equal. The PR addresses it by using the arrays' content to compute the hash, like the equals method does. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7860 Reviewed By: jay-zhuang Differential Revision: D25901327 Pulled By: akankshamahajan15 fbshipit-source-id: 347e7b3d2ba7befe7faa956b033e6421b9d0c235
This commit is contained in:
parent
8e7b068ecc
commit
0426d4a4ee
|
@ -115,7 +115,9 @@ public class ColumnFamilyHandle extends RocksObject {
|
|||
@Override
|
||||
public int hashCode() {
|
||||
try {
|
||||
return Objects.hash(getName(), getID(), rocksDB_.nativeHandle_);
|
||||
int result = Objects.hash(getID(), rocksDB_.nativeHandle_);
|
||||
result = 31 * result + Arrays.hashCode(getName());
|
||||
return result;
|
||||
} catch (RocksDBException e) {
|
||||
throw new RuntimeException("Cannot calculate hash code of column family handle", e);
|
||||
}
|
||||
|
|
|
@ -156,8 +156,10 @@ public class CapturingWriteBatchHandler extends WriteBatch.Handler {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(action, columnFamilyId, key, value);
|
||||
int result = Objects.hash(action, columnFamilyId);
|
||||
result = 31 * result + Arrays.hashCode(key);
|
||||
result = 31 * result + Arrays.hashCode(value);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue