From 16451b0b8dfdb095784dede8160a6cb34e2370ea Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Fri, 4 Feb 2022 20:59:26 +0000 Subject: [PATCH] Use Arrays.hashCode in EventIndex hashCode() The hashCode method on arrays does not actually hash the array contents but instead is just the identity of the array itself. This will return erroneous results for objects that are equal but not the exact same instance. Bug: 217923092 Test: errorprone build Change-Id: Idfcc220da5fb07a9b24a7b12795466303b14e35a --- services/Android.bp | 1 + .../people/java/com/android/server/people/data/EventIndex.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/Android.bp b/services/Android.bp index b40034abb1728..db233e57c9445 100644 --- a/services/Android.bp +++ b/services/Android.bp @@ -21,6 +21,7 @@ java_defaults { "-Xep:TryFailThrowable:ERROR", "-Xep:HashtableContains:ERROR", "-Xep:FormatString:ERROR", + "-Xep:ArrayHashCode:ERROR", // NOTE: only enable to generate local patchfiles // "-XepPatchChecks:refaster:frameworks/base/errorprone/refaster/EfficientXml.java.refaster", // "-XepPatchLocation:/tmp/refaster/", diff --git a/services/people/java/com/android/server/people/data/EventIndex.java b/services/people/java/com/android/server/people/data/EventIndex.java index 6a13b0e6dd6ee..02afb8d1cc183 100644 --- a/services/people/java/com/android/server/people/data/EventIndex.java +++ b/services/people/java/com/android/server/people/data/EventIndex.java @@ -254,7 +254,7 @@ public class EventIndex { @Override public int hashCode() { - return Objects.hash(mLastUpdatedTime, mEventBitmaps); + return Objects.hash(mLastUpdatedTime, Arrays.hashCode(mEventBitmaps)); } synchronized void writeToProto(@NonNull ProtoOutputStream protoOutputStream) {