Skip to content

Commit

Permalink
Avoid calling UriLoader with unsupported schemes from StringLoader.
Browse files Browse the repository at this point in the history
Related to bumptech#2894.
  • Loading branch information
sjudd committed Apr 25, 2018
1 parent 11a83f8 commit ff463d7
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ public StringLoader(ModelLoader<Uri, Data> uriLoader) {
public LoadData<Data> 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;
}

Expand Down Expand Up @@ -66,7 +71,8 @@ public static class StreamFactory implements ModelLoaderFactory<String, InputStr

@NonNull
@Override
public ModelLoader<String, InputStream> build(MultiModelLoaderFactory multiFactory) {
public ModelLoader<String, InputStream> build(
@NonNull MultiModelLoaderFactory multiFactory) {
return new StringLoader<>(multiFactory.build(Uri.class, InputStream.class));
}

Expand All @@ -84,7 +90,8 @@ public static class FileDescriptorFactory

@NonNull
@Override
public ModelLoader<String, ParcelFileDescriptor> build(MultiModelLoaderFactory multiFactory) {
public ModelLoader<String, ParcelFileDescriptor> build(
@NonNull MultiModelLoaderFactory multiFactory) {
return new StringLoader<>(multiFactory.build(Uri.class, ParcelFileDescriptor.class));
}

Expand All @@ -101,7 +108,8 @@ public static final class AssetFileDescriptorFactory
implements ModelLoaderFactory<String, AssetFileDescriptor> {

@Override
public ModelLoader<String, AssetFileDescriptor> build(MultiModelLoaderFactory multiFactory) {
public ModelLoader<String, AssetFileDescriptor> build(
@NonNull MultiModelLoaderFactory multiFactory) {
return new StringLoader<>(multiFactory.build(Uri.class, AssetFileDescriptor.class));
}

Expand Down

0 comments on commit ff463d7

Please sign in to comment.