Skip to content

Commit

Permalink
Fix an NPE in ResourceDrawableDecoder.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sjudd committed Dec 27, 2017
1 parent 7d35039 commit d522ac7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public boolean handles(@NonNull Uri source, @NonNull Options options) {
public Resource<Bitmap> decode(@NonNull Uri source, int width, int height,
@NonNull Options options) {
Resource<Drawable> drawableResource = drawableDecoder.decode(source, width, height, options);
if (drawableResource == null) {
return null;
}
Drawable drawable = drawableResource.get();
return DrawableToBitmapConverter.convert(bitmapPool, drawable, width, height);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -11,8 +12,9 @@
final class NonOwnedDrawableResource extends DrawableResource<Drawable> {

@SuppressWarnings("unchecked")
static Resource<Drawable> newInstance(Drawable drawable) {
return new NonOwnedDrawableResource(drawable);
@Nullable
static Resource<Drawable> newInstance(@Nullable Drawable drawable) {
return drawable != null ? new NonOwnedDrawableResource(drawable) : null;
}

private NonOwnedDrawableResource(Drawable drawable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Drawable> decode(@NonNull Uri source, int width, int height,
@NonNull Options options) {
Expand Down

0 comments on commit d522ac7

Please sign in to comment.