Skip to content

Commit 5b786da

Browse files
Googlercopybara-github
Googler
authored andcommitted
Remote: correctly implement equals and hashCode.
PiperOrigin-RevId: 352516263
1 parent 0b2af6f commit 5b786da

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,15 @@ public boolean equals(Object o) {
577577
RemoteFileArtifactValue that = (RemoteFileArtifactValue) o;
578578
return Arrays.equals(digest, that.digest)
579579
&& size == that.size
580-
&& locationIndex == that.locationIndex;
580+
&& locationIndex == that.locationIndex
581+
&& Objects.equals(actionId, that.actionId)
582+
&& dataIsShareable() == that.dataIsShareable();
581583
}
582584

583585
@Override
584586
public int hashCode() {
585-
return Objects.hash(Arrays.hashCode(digest), size, locationIndex, dataIsShareable());
587+
return Objects.hash(
588+
Arrays.hashCode(digest), size, locationIndex, actionId, dataIsShareable());
586589
}
587590

588591
@Override

src/main/java/com/google/devtools/build/lib/remote/common/RemoteActionFileArtifactValue.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package com.google.devtools.build.lib.remote.common;
1515

1616
import com.google.devtools.build.lib.actions.FileArtifactValue.RemoteFileArtifactValue;
17+
import java.util.Arrays;
18+
import java.util.Objects;
1719

1820
/**
1921
* A {@link RemoteFileArtifactValue} with additional data only available when using Remote Execution
@@ -32,4 +34,30 @@ public RemoteActionFileArtifactValue(
3234
public boolean isExecutable() {
3335
return isExecutable;
3436
}
37+
38+
@Override
39+
public boolean equals(Object o) {
40+
if (!(o instanceof RemoteActionFileArtifactValue)) {
41+
return false;
42+
}
43+
44+
RemoteActionFileArtifactValue that = (RemoteActionFileArtifactValue) o;
45+
return Arrays.equals(getDigest(), that.getDigest())
46+
&& getSize() == that.getSize()
47+
&& getLocationIndex() == that.getLocationIndex()
48+
&& Objects.equals(getActionId(), that.getActionId())
49+
&& isExecutable == that.isExecutable
50+
&& dataIsShareable() == that.dataIsShareable();
51+
}
52+
53+
@Override
54+
public int hashCode() {
55+
return Objects.hash(
56+
Arrays.hashCode(getDigest()),
57+
getSize(),
58+
getLocationIndex(),
59+
getActionId(),
60+
isExecutable,
61+
dataIsShareable());
62+
}
3563
}

src/main/java/com/google/devtools/build/lib/remote/merkletree/DirectoryTree.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public boolean isExecutable() {
108108

109109
@Override
110110
public int hashCode() {
111-
return Objects.hash(super.hashCode(), path, data, digest);
111+
return Objects.hash(super.hashCode(), path, data, digest, isExecutable);
112112
}
113113

114114
@Override
@@ -118,7 +118,8 @@ public boolean equals(Object o) {
118118
return super.equals(other)
119119
&& Objects.equals(path, other.path)
120120
&& Objects.equals(data, other.data)
121-
&& Objects.equals(digest, other.digest);
121+
&& Objects.equals(digest, other.digest)
122+
&& isExecutable == other.isExecutable;
122123
}
123124
return false;
124125
}

0 commit comments

Comments
 (0)