From ff463d779ef8bccffc224e3647dbaf6dbc27fd57 Mon Sep 17 00:00:00 2001 From: Sam Judd Date: Wed, 25 Apr 2018 10:17:37 -0700 Subject: [PATCH] Avoid calling UriLoader with unsupported schemes from StringLoader. Related to #2894. --- .../bumptech/glide/load/model/StringLoader.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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)); }