From 5b786da75837c5e29714e1d708c3cdf9a67ed32d Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 19 Jan 2021 01:20:37 -0800 Subject: [PATCH] Remote: correctly implement equals and hashCode. PiperOrigin-RevId: 352516263 --- .../build/lib/actions/FileArtifactValue.java | 7 +++-- .../common/RemoteActionFileArtifactValue.java | 28 +++++++++++++++++++ .../lib/remote/merkletree/DirectoryTree.java | 5 ++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java b/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java index 6c59363fe0ad40..547b3cc13ba390 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java +++ b/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java @@ -577,12 +577,15 @@ public boolean equals(Object o) { RemoteFileArtifactValue that = (RemoteFileArtifactValue) o; return Arrays.equals(digest, that.digest) && size == that.size - && locationIndex == that.locationIndex; + && locationIndex == that.locationIndex + && Objects.equals(actionId, that.actionId) + && dataIsShareable() == that.dataIsShareable(); } @Override public int hashCode() { - return Objects.hash(Arrays.hashCode(digest), size, locationIndex, dataIsShareable()); + return Objects.hash( + Arrays.hashCode(digest), size, locationIndex, actionId, dataIsShareable()); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/remote/common/RemoteActionFileArtifactValue.java b/src/main/java/com/google/devtools/build/lib/remote/common/RemoteActionFileArtifactValue.java index a4d9f8042ab7a2..e3e96f66bf58b9 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/common/RemoteActionFileArtifactValue.java +++ b/src/main/java/com/google/devtools/build/lib/remote/common/RemoteActionFileArtifactValue.java @@ -14,6 +14,8 @@ package com.google.devtools.build.lib.remote.common; import com.google.devtools.build.lib.actions.FileArtifactValue.RemoteFileArtifactValue; +import java.util.Arrays; +import java.util.Objects; /** * A {@link RemoteFileArtifactValue} with additional data only available when using Remote Execution @@ -32,4 +34,30 @@ public RemoteActionFileArtifactValue( public boolean isExecutable() { return isExecutable; } + + @Override + public boolean equals(Object o) { + if (!(o instanceof RemoteActionFileArtifactValue)) { + return false; + } + + RemoteActionFileArtifactValue that = (RemoteActionFileArtifactValue) o; + return Arrays.equals(getDigest(), that.getDigest()) + && getSize() == that.getSize() + && getLocationIndex() == that.getLocationIndex() + && Objects.equals(getActionId(), that.getActionId()) + && isExecutable == that.isExecutable + && dataIsShareable() == that.dataIsShareable(); + } + + @Override + public int hashCode() { + return Objects.hash( + Arrays.hashCode(getDigest()), + getSize(), + getLocationIndex(), + getActionId(), + isExecutable, + dataIsShareable()); + } } diff --git a/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java b/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java index 948731016a904f..19d4b33c4e1ccb 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java +++ b/src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java @@ -108,7 +108,7 @@ public boolean isExecutable() { @Override public int hashCode() { - return Objects.hash(super.hashCode(), path, data, digest); + return Objects.hash(super.hashCode(), path, data, digest, isExecutable); } @Override @@ -118,7 +118,8 @@ public boolean equals(Object o) { return super.equals(other) && Objects.equals(path, other.path) && Objects.equals(data, other.data) - && Objects.equals(digest, other.digest); + && Objects.equals(digest, other.digest) + && isExecutable == other.isExecutable; } return false; }