Skip to content

Commit

Permalink
Make RegularFileArtifactValue#toString not crash if the digest is n…
Browse files Browse the repository at this point in the history
…ull.

Observed NPE in a debugger that was trying to show a string representation.

Also make the string representation of the digest consistent with `RemoteFileArtifactValue`.

PiperOrigin-RevId: 595554648
Change-Id: I705ed0ffabf4bde81bb3b1f653f30b7565e65b82
  • Loading branch information
justinhorvitz authored and copybara-github committed Jan 4, 2024
1 parent 81e1333 commit dc3a359
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ public static FileArtifactValue createProxy(byte[] digest) {
return createForNormalFile(digest, /* proxy= */ null, /* size= */ 0);
}

private static String bytesToString(byte[] bytes) {
return "0x" + BaseEncoding.base16().omitPadding().encode(bytes);
private static String bytesToString(@Nullable byte[] bytes) {
return bytes == null ? "null" : "0x" + BaseEncoding.base16().omitPadding().encode(bytes);
}

private static final class DirectoryArtifactValue extends FileArtifactValue {
Expand Down Expand Up @@ -541,7 +541,7 @@ public long getModifiedTime() {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("digest", BaseEncoding.base16().lowerCase().encode(digest))
.add("digest", bytesToString(digest))
.add("size", size)
.add("proxy", proxy)
.toString();
Expand Down

0 comments on commit dc3a359

Please sign in to comment.