Skip to content

Commit

Permalink
Remote: correctly implement equals and hashCode.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 352516263
  • Loading branch information
Googler authored and copybara-github committed Jan 19, 2021
1 parent 0b2af6f commit 5b786da
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit 5b786da

Please sign in to comment.