diff --git a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java index 211936b20e..c95f61a123 100644 --- a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java +++ b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java @@ -4,6 +4,8 @@ import android.content.res.Resources.Theme; import android.graphics.drawable.Drawable; import android.util.Log; + +import androidx.annotation.AnyRes; import androidx.annotation.DrawableRes; import androidx.annotation.GuardedBy; import androidx.annotation.NonNull; @@ -387,7 +389,7 @@ public boolean isAnyResourceSet() { private Drawable getErrorDrawable() { if (errorDrawable == null) { errorDrawable = requestOptions.getErrorPlaceholder(); - if (errorDrawable == null && requestOptions.getErrorId() > 0) { + if (errorDrawable == null && isValidId(requestOptions.getErrorId())) { errorDrawable = loadDrawable(requestOptions.getErrorId()); } } @@ -398,7 +400,7 @@ private Drawable getErrorDrawable() { private Drawable getPlaceholderDrawable() { if (placeholderDrawable == null) { placeholderDrawable = requestOptions.getPlaceholderDrawable(); - if (placeholderDrawable == null && requestOptions.getPlaceholderId() > 0) { + if (placeholderDrawable == null && isValidId(requestOptions.getPlaceholderId())) { placeholderDrawable = loadDrawable(requestOptions.getPlaceholderId()); } } @@ -409,13 +411,20 @@ private Drawable getPlaceholderDrawable() { private Drawable getFallbackDrawable() { if (fallbackDrawable == null) { fallbackDrawable = requestOptions.getFallbackDrawable(); - if (fallbackDrawable == null && requestOptions.getFallbackId() > 0) { + if (fallbackDrawable == null && isValidId(requestOptions.getFallbackId())) { fallbackDrawable = loadDrawable(requestOptions.getFallbackId()); } } return fallbackDrawable; } + /** + * @see android.content.res.ResourceId.isValid + */ + private static boolean isValidId(int id) { + return id != -1 && (id & 0xff000000) != 0 && (id & 0x00ff0000) != 0; + } + @GuardedBy("requestLock") private Drawable loadDrawable(@DrawableRes int resourceId) { Theme theme =