Skip to content

Commit 6981250

Browse files
committed
Fix ResourceID validation check expression
1 parent f452e11 commit 6981250

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

library/src/main/java/com/bumptech/glide/request/SingleRequest.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import android.content.res.Resources.Theme;
55
import android.graphics.drawable.Drawable;
66
import android.util.Log;
7+
8+
import androidx.annotation.AnyRes;
79
import androidx.annotation.DrawableRes;
810
import androidx.annotation.GuardedBy;
911
import androidx.annotation.NonNull;
@@ -387,8 +389,7 @@ public boolean isAnyResourceSet() {
387389
private Drawable getErrorDrawable() {
388390
if (errorDrawable == null) {
389391
errorDrawable = requestOptions.getErrorPlaceholder();
390-
if (errorDrawable == null && requestOptions.getErrorId() != -1 &&
391-
(requestOptions.getErrorId() & 0xff000000) != 0 && (requestOptions.getErrorId() & 0x00ff0000) != 0) {
392+
if (errorDrawable == null && isValidId(requestOptions.getErrorId())) {
392393
errorDrawable = loadDrawable(requestOptions.getErrorId());
393394
}
394395
}
@@ -399,8 +400,7 @@ private Drawable getErrorDrawable() {
399400
private Drawable getPlaceholderDrawable() {
400401
if (placeholderDrawable == null) {
401402
placeholderDrawable = requestOptions.getPlaceholderDrawable();
402-
if (placeholderDrawable == null && requestOptions.getPlaceholderId() != -1 &&
403-
(requestOptions.getPlaceholderId() & 0xff000000) != 0 && (requestOptions.getPlaceholderId() & 0x00ff0000) != 0) {
403+
if (placeholderDrawable == null && isValidId(requestOptions.getPlaceholderId())) {
404404
placeholderDrawable = loadDrawable(requestOptions.getPlaceholderId());
405405
}
406406
}
@@ -411,14 +411,20 @@ private Drawable getPlaceholderDrawable() {
411411
private Drawable getFallbackDrawable() {
412412
if (fallbackDrawable == null) {
413413
fallbackDrawable = requestOptions.getFallbackDrawable();
414-
if (fallbackDrawable == null && requestOptions.getFallbackId() != -1 &&
415-
(requestOptions.getFallbackId() & 0xff000000) != 0 && (requestOptions.getFallbackId() & 0x00ff0000) != 0) {
414+
if (fallbackDrawable == null && isValidId(requestOptions.getFallbackId())) {
416415
fallbackDrawable = loadDrawable(requestOptions.getFallbackId());
417416
}
418417
}
419418
return fallbackDrawable;
420419
}
421420

421+
/**
422+
* @see android.content.res.ResourceId.isValid
423+
*/
424+
private static boolean isValidId(int id) {
425+
return id != -1 && (id & 0xff000000) != 0 && (id & 0x00ff0000) != 0;
426+
}
427+
422428
@GuardedBy("requestLock")
423429
private Drawable loadDrawable(@DrawableRes int resourceId) {
424430
Theme theme =

0 commit comments

Comments
 (0)