From c67663cbc8c5661f47fb8477f2540739ddc194e1 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 26 May 2017 09:46:48 +0100 Subject: [PATCH] Fix Error Prone ArrayEquals/ArrayHashCode bugs This will change behavior so it could break tests but if it does it is because they relied on broken behavior. Someone on the frameworks team will need to verify the correctness of these changes and fix any knock on effects. See the following for a description of the bugs: * http://errorprone.info/bugpattern/ArrayEquals * http://errorprone.info/bugpattern/ArrayHashCode Fixed automatically by Error Prone apart from manual changes to fix up the formatting (Error Prone expects google-java-format) and to change Object.deepEquals to Arrays.equals for consistency with Arrays.hashCode. Test: make checkbuild Change-Id: I1528b795b77a4f1e0c4e7e66ad4f924b7a7606f6 --- core/java/android/app/job/JobInfo.java | 45 +++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/core/java/android/app/job/JobInfo.java b/core/java/android/app/job/JobInfo.java index 3cb59f27bfafe..87e516cabba54 100644 --- a/core/java/android/app/job/JobInfo.java +++ b/core/java/android/app/job/JobInfo.java @@ -35,6 +35,7 @@ import android.util.Log; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; +import java.util.Arrays; import java.util.Objects; /** @@ -501,7 +502,7 @@ public class JobInfo implements Parcelable { if (constraintFlags != j.constraintFlags) { return false; } - if (!Objects.deepEquals(triggerContentUris, j.triggerContentUris)) { + if (!Arrays.equals(triggerContentUris, j.triggerContentUris)) { return false; } if (triggerContentUpdateDelay != j.triggerContentUpdateDelay) { @@ -556,37 +557,37 @@ public class JobInfo implements Parcelable { public int hashCode() { int hashCode = jobId; if (extras != null) { - hashCode = 31*hashCode + extras.hashCode(); + hashCode = 31 * hashCode + extras.hashCode(); } if (transientExtras != null) { - hashCode = 31*hashCode + transientExtras.hashCode(); + hashCode = 31 * hashCode + transientExtras.hashCode(); } if (clipData != null) { - hashCode = 31*hashCode + clipData.hashCode(); + hashCode = 31 * hashCode + clipData.hashCode(); } hashCode = 31*hashCode + clipGrantFlags; if (service != null) { - hashCode = 31*hashCode + service.hashCode(); + hashCode = 31 * hashCode + service.hashCode(); } - hashCode = 31*hashCode + constraintFlags; + hashCode = 31 * hashCode + constraintFlags; if (triggerContentUris != null) { - hashCode = 31*hashCode + triggerContentUris.hashCode(); + hashCode = 31 * hashCode + Arrays.hashCode(triggerContentUris); } - hashCode = 31*hashCode + Long.hashCode(triggerContentUpdateDelay); - hashCode = 31*hashCode + Long.hashCode(triggerContentMaxDelay); - hashCode = 31*hashCode + Boolean.hashCode(hasEarlyConstraint); - hashCode = 31*hashCode + Boolean.hashCode(hasLateConstraint); - hashCode = 31*hashCode + networkType; - hashCode = 31*hashCode + Long.hashCode(minLatencyMillis); - hashCode = 31*hashCode + Long.hashCode(maxExecutionDelayMillis); - hashCode = 31*hashCode + Boolean.hashCode(isPeriodic); - hashCode = 31*hashCode + Boolean.hashCode(isPersisted); - hashCode = 31*hashCode + Long.hashCode(intervalMillis); - hashCode = 31*hashCode + Long.hashCode(flexMillis); - hashCode = 31*hashCode + Long.hashCode(initialBackoffMillis); - hashCode = 31*hashCode + backoffPolicy; - hashCode = 31*hashCode + priority; - hashCode = 31*hashCode + flags; + hashCode = 31 * hashCode + Long.hashCode(triggerContentUpdateDelay); + hashCode = 31 * hashCode + Long.hashCode(triggerContentMaxDelay); + hashCode = 31 * hashCode + Boolean.hashCode(hasEarlyConstraint); + hashCode = 31 * hashCode + Boolean.hashCode(hasLateConstraint); + hashCode = 31 * hashCode + networkType; + hashCode = 31 * hashCode + Long.hashCode(minLatencyMillis); + hashCode = 31 * hashCode + Long.hashCode(maxExecutionDelayMillis); + hashCode = 31 * hashCode + Boolean.hashCode(isPeriodic); + hashCode = 31 * hashCode + Boolean.hashCode(isPersisted); + hashCode = 31 * hashCode + Long.hashCode(intervalMillis); + hashCode = 31 * hashCode + Long.hashCode(flexMillis); + hashCode = 31 * hashCode + Long.hashCode(initialBackoffMillis); + hashCode = 31 * hashCode + backoffPolicy; + hashCode = 31 * hashCode + priority; + hashCode = 31 * hashCode + flags; return hashCode; }