diff --git a/library/src/main/java/com/bumptech/glide/load/model/StringLoader.java b/library/src/main/java/com/bumptech/glide/load/model/StringLoader.java index 16bb6cfde5..c00fac18ed 100644 --- a/library/src/main/java/com/bumptech/glide/load/model/StringLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/model/StringLoader.java @@ -29,11 +29,16 @@ public StringLoader(ModelLoader uriLoader) { public LoadData buildLoadData(@NonNull String model, int width, int height, @NonNull Options options) { Uri uri = parseUri(model); - return uri == null ? null : uriLoader.buildLoadData(uri, width, height, options); + if (uri == null || !uriLoader.handles(uri)) { + return null; + } + return uriLoader.buildLoadData(uri, width, height, options); } @Override public boolean handles(@NonNull String model) { + // Avoid parsing the Uri twice and simply return null from buildLoadData if we don't handle this + // particular Uri type. return true; } @@ -66,7 +71,8 @@ public static class StreamFactory implements ModelLoaderFactory build(MultiModelLoaderFactory multiFactory) { + public ModelLoader build( + @NonNull MultiModelLoaderFactory multiFactory) { return new StringLoader<>(multiFactory.build(Uri.class, InputStream.class)); } @@ -84,7 +90,8 @@ public static class FileDescriptorFactory @NonNull @Override - public ModelLoader build(MultiModelLoaderFactory multiFactory) { + public ModelLoader build( + @NonNull MultiModelLoaderFactory multiFactory) { return new StringLoader<>(multiFactory.build(Uri.class, ParcelFileDescriptor.class)); } @@ -101,7 +108,8 @@ public static final class AssetFileDescriptorFactory implements ModelLoaderFactory { @Override - public ModelLoader build(MultiModelLoaderFactory multiFactory) { + public ModelLoader build( + @NonNull MultiModelLoaderFactory multiFactory) { return new StringLoader<>(multiFactory.build(Uri.class, AssetFileDescriptor.class)); }