Fix Giphy crash

This commit is contained in:
nielsandriesse 2020-07-21 11:51:01 +10:00
parent 58c9b70c19
commit a95da2c219

View File

@ -14,7 +14,7 @@ public class ChunkedImageUrl implements Key {
public static final long SIZE_UNKNOWN = -1; public static final long SIZE_UNKNOWN = -1;
private final String url; private final String url;
private final long size; private final long size;
public ChunkedImageUrl(@NonNull String url) { public ChunkedImageUrl(@NonNull String url) {
this(url, SIZE_UNKNOWN); this(url, SIZE_UNKNOWN);
@ -22,7 +22,7 @@ public class ChunkedImageUrl implements Key {
public ChunkedImageUrl(@NonNull String url, long size) { public ChunkedImageUrl(@NonNull String url, long size) {
this.url = url; this.url = url;
this.size = size; this.size = size;
} }
public String getUrl() { public String getUrl() {
@ -35,6 +35,7 @@ public class ChunkedImageUrl implements Key {
@Override @Override
public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
if (url == null) { return; }
messageDigest.update(url.getBytes()); messageDigest.update(url.getBytes());
messageDigest.update(Conversions.longToByteArray(size)); messageDigest.update(Conversions.longToByteArray(size));
} }
@ -45,12 +46,14 @@ public class ChunkedImageUrl implements Key {
ChunkedImageUrl that = (ChunkedImageUrl)other; ChunkedImageUrl that = (ChunkedImageUrl)other;
if (this.url == null || that.url == null) { return false; }
return this.url.equals(that.url) && this.size == that.size; return this.url.equals(that.url) && this.size == that.size;
} }
@Override @Override
public int hashCode() { public int hashCode() {
if (url == null) { return 0; }
return url.hashCode() ^ (int)size; return url.hashCode() ^ (int)size;
} }
} }