Skip to content

Commit

Permalink
Fix divergent equals and hashCode behavior
Browse files Browse the repository at this point in the history
Calling Objects.hash with a byte[] will call the identity hashCode on
the byte[] and this doesn't agree with the use of Objects.deepEquals
in equals.
Bug caught by error prone.

Also, replaced usage of Objects.deepEquals(mServiceDataUuid, ...) with
Objects.equals(mServiceDataUuid, ...), because mServiceDataUuid
is an Object of type ParcelUuid.

Bug: 28585195
Change-Id: Id92734874339985fedafe1a28286a6a4dcd88d3b
  • Loading branch information
Pavlin Radoslavov committed May 6, 2016
1 parent e3a25ad commit f74b830
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions core/java/android/bluetooth/le/ScanFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,13 @@ public String toString() {

@Override
public int hashCode() {
return Objects.hash(mDeviceName, mDeviceAddress, mManufacturerId, mManufacturerData,
mManufacturerDataMask, mServiceDataUuid, mServiceData, mServiceDataMask,
mServiceUuid, mServiceUuidMask);
return Objects.hash(mDeviceName, mDeviceAddress, mManufacturerId,
Arrays.hashCode(mManufacturerData),
Arrays.hashCode(mManufacturerDataMask),
mServiceDataUuid,
Arrays.hashCode(mServiceData),
Arrays.hashCode(mServiceDataMask),
mServiceUuid, mServiceUuidMask);
}

@Override
Expand All @@ -401,10 +405,10 @@ public boolean equals(Object obj) {
ScanFilter other = (ScanFilter) obj;
return Objects.equals(mDeviceName, other.mDeviceName) &&
Objects.equals(mDeviceAddress, other.mDeviceAddress) &&
mManufacturerId == other.mManufacturerId &&
mManufacturerId == other.mManufacturerId &&
Objects.deepEquals(mManufacturerData, other.mManufacturerData) &&
Objects.deepEquals(mManufacturerDataMask, other.mManufacturerDataMask) &&
Objects.deepEquals(mServiceDataUuid, other.mServiceDataUuid) &&
Objects.equals(mServiceDataUuid, other.mServiceDataUuid) &&
Objects.deepEquals(mServiceData, other.mServiceData) &&
Objects.deepEquals(mServiceDataMask, other.mServiceDataMask) &&
Objects.equals(mServiceUuid, other.mServiceUuid) &&
Expand Down

0 comments on commit f74b830

Please sign in to comment.