From d522ac7249ca1bf71f6de30e62d71a1faa8d4c4c Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Sun, 24 Dec 2017 17:32:14 -0800 Subject: [PATCH] Fix an NPE in ResourceDrawableDecoder. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NPE would only occur if the load was going to fail for the decoder anyway, but at least this way we don’t show a scary looking NPE for an expected case. --- .../glide/load/resource/bitmap/ResourceBitmapDecoder.java | 3 +++ .../load/resource/drawable/NonOwnedDrawableResource.java | 6 ++++-- .../load/resource/drawable/ResourceDrawableDecoder.java | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ResourceBitmapDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ResourceBitmapDecoder.java index e888fd5c19..3ef5b5b3e8 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ResourceBitmapDecoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ResourceBitmapDecoder.java @@ -48,6 +48,9 @@ public boolean handles(@NonNull Uri source, @NonNull Options options) { public Resource decode(@NonNull Uri source, int width, int height, @NonNull Options options) { Resource drawableResource = drawableDecoder.decode(source, width, height, options); + if (drawableResource == null) { + return null; + } Drawable drawable = drawableResource.get(); return DrawableToBitmapConverter.convert(bitmapPool, drawable, width, height); } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/drawable/NonOwnedDrawableResource.java b/library/src/main/java/com/bumptech/glide/load/resource/drawable/NonOwnedDrawableResource.java index 09b327382d..2cba884622 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/drawable/NonOwnedDrawableResource.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/drawable/NonOwnedDrawableResource.java @@ -2,6 +2,7 @@ import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.bumptech.glide.load.engine.Resource; /** @@ -11,8 +12,9 @@ final class NonOwnedDrawableResource extends DrawableResource { @SuppressWarnings("unchecked") - static Resource newInstance(Drawable drawable) { - return new NonOwnedDrawableResource(drawable); + @Nullable + static Resource newInstance(@Nullable Drawable drawable) { + return drawable != null ? new NonOwnedDrawableResource(drawable) : null; } private NonOwnedDrawableResource(Drawable drawable) { diff --git a/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java index da440845a5..1550ef519e 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java @@ -7,6 +7,7 @@ import android.net.Uri; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.ResourceDecoder; import com.bumptech.glide.load.engine.Resource; @@ -40,7 +41,7 @@ public boolean handles(@NonNull Uri source, @NonNull Options options) { return source.getScheme().equals(ContentResolver.SCHEME_ANDROID_RESOURCE); } - @NonNull + @Nullable @Override public Resource decode(@NonNull Uri source, int width, int height, @NonNull Options options) {