From c3dafde00a061bafcd43a739336ca3503af13a7d Mon Sep 17 00:00:00 2001
From: Alex Saveau
Date: Tue, 5 Dec 2017 19:23:56 -0800
Subject: [PATCH] Add nullability annotations to okhttp3 module and its
dependencies (#2685)
* Add nullability annotations to okhttp3 module and its dependencies
Signed-off-by: Alex Saveau
---
.../okhttp3/OkHttpLibraryGlideModule.java | 4 +++-
.../integration/okhttp3/OkHttpStreamFetcher.java | 2 +-
.../glide/integration/okhttp3/OkHttpUrlLoader.java | 12 +++++++-----
.../integration/volley/VolleyLibraryGlideModule.java | 4 +++-
.../glide/integration/volley/VolleyUrlLoader.java | 7 ++++---
.../bumptech/glide/load/model/AssetUriLoader.java | 7 ++++---
.../bumptech/glide/load/model/ByteArrayLoader.java | 4 ++--
.../glide/load/model/ByteBufferFileLoader.java | 6 +++---
.../com/bumptech/glide/load/model/DataUrlLoader.java | 5 +++--
.../com/bumptech/glide/load/model/FileLoader.java | 6 +++---
.../glide/load/model/MediaStoreFileLoader.java | 7 ++++---
.../com/bumptech/glide/load/model/ModelLoader.java | 6 ++++--
.../bumptech/glide/load/model/MultiModelLoader.java | 6 +++---
.../glide/load/model/MultiModelLoaderFactory.java | 6 ++++--
.../bumptech/glide/load/model/ResourceLoader.java | 6 ++++--
.../com/bumptech/glide/load/model/StringLoader.java | 7 ++++---
.../bumptech/glide/load/model/UnitModelLoader.java | 6 +++---
.../com/bumptech/glide/load/model/UriLoader.java | 7 ++++---
.../com/bumptech/glide/load/model/UrlUriLoader.java | 6 ++++--
.../glide/load/model/stream/BaseGlideUrlLoader.java | 4 +++-
.../glide/load/model/stream/HttpGlideUrlLoader.java | 7 ++++---
.../glide/load/model/stream/HttpUriLoader.java | 6 ++++--
.../model/stream/MediaStoreImageThumbLoader.java | 6 ++++--
.../model/stream/MediaStoreVideoThumbLoader.java | 6 ++++--
.../bumptech/glide/load/model/stream/UrlLoader.java | 6 ++++--
.../bumptech/glide/module/LibraryGlideModule.java | 4 +++-
.../bumptech/glide/module/RegistersComponents.java | 4 +++-
.../load/model/stream/BaseGlideUrlLoaderTest.java | 8 ++++----
.../glide/samples/flickr/FlickrGlideModule.java | 4 +++-
.../glide/samples/flickr/FlickrModelLoader.java | 3 ++-
.../glide/samples/giphy/GiphyGlideModule.java | 4 +++-
.../glide/samples/giphy/GiphyModelLoader.java | 3 ++-
.../com/bumptech/glide/samples/svg/SvgModule.java | 4 +++-
33 files changed, 113 insertions(+), 70 deletions(-)
diff --git a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java
index 74eace9eb4..b315acbd79 100644
--- a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java
+++ b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java
@@ -1,6 +1,7 @@
package com.bumptech.glide.integration.okhttp3;
import android.content.Context;
+import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
@@ -19,7 +20,8 @@
@GlideModule
public final class OkHttpLibraryGlideModule extends LibraryGlideModule {
@Override
- public void registerComponents(Context context, Glide glide, Registry registry) {
+ public void registerComponents(@NonNull Context context, @NonNull Glide glide,
+ @NonNull Registry registry) {
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
}
}
diff --git a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java
index f795fa2a32..7ffd81db6c 100644
--- a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java
+++ b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java
@@ -77,7 +77,7 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) {
}
@Override
- public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
+ public void onResponse(@NonNull Call call, @NonNull Response response) {
responseBody = response.body();
if (response.isSuccessful()) {
long contentLength = Preconditions.checkNotNull(responseBody).contentLength();
diff --git a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java
index de8e2752ff..8f8f9066c5 100644
--- a/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java
+++ b/integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java
@@ -1,5 +1,6 @@
package com.bumptech.glide.integration.okhttp3;
+import android.support.annotation.NonNull;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.ModelLoader;
@@ -18,18 +19,18 @@ public class OkHttpUrlLoader implements ModelLoader {
// Public API.
@SuppressWarnings("WeakerAccess")
- public OkHttpUrlLoader(Call.Factory client) {
+ public OkHttpUrlLoader(@NonNull Call.Factory client) {
this.client = client;
}
@Override
- public boolean handles(GlideUrl url) {
+ public boolean handles(@NonNull GlideUrl url) {
return true;
}
@Override
- public LoadData buildLoadData(GlideUrl model, int width, int height,
- Options options) {
+ public LoadData buildLoadData(@NonNull GlideUrl model, int width, int height,
+ @NonNull Options options) {
return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
}
@@ -65,10 +66,11 @@ public Factory() {
*
* @param client this is typically an instance of {@code OkHttpClient}.
*/
- public Factory(Call.Factory client) {
+ public Factory(@NonNull Call.Factory client) {
this.client = client;
}
+ @NonNull
@Override
public ModelLoader build(MultiModelLoaderFactory multiFactory) {
return new OkHttpUrlLoader(client);
diff --git a/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java b/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java
index 6fa56468cb..514c62008d 100644
--- a/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java
+++ b/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java
@@ -1,6 +1,7 @@
package com.bumptech.glide.integration.volley;
import android.content.Context;
+import android.support.annotation.NonNull;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
@@ -21,7 +22,8 @@
@GlideModule
public class VolleyLibraryGlideModule extends LibraryGlideModule {
@Override
- public void registerComponents(Context context, Glide glide, Registry registry) {
+ public void registerComponents(@NonNull Context context, @NonNull Glide glide,
+ @NonNull Registry registry) {
registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
}
}
diff --git a/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java b/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java
index 700a8a7d45..d64a47d409 100644
--- a/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java
+++ b/integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java
@@ -1,6 +1,7 @@
package com.bumptech.glide.integration.volley;
import android.content.Context;
+import android.support.annotation.NonNull;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.load.Options;
@@ -32,13 +33,13 @@ public VolleyUrlLoader(RequestQueue requestQueue, VolleyRequestFactory requestFa
}
@Override
- public boolean handles(GlideUrl url) {
+ public boolean handles(@NonNull GlideUrl url) {
return true;
}
@Override
- public LoadData buildLoadData(GlideUrl url, int width, int height,
- Options options) {
+ public LoadData buildLoadData(@NonNull GlideUrl url, int width, int height,
+ @NonNull Options options) {
return new LoadData<>(url, new VolleyStreamFetcher(requestQueue, url, requestFactory));
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java b/library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java
index f60999c6ae..f8af6151b0 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java
@@ -4,6 +4,7 @@
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
+import android.support.annotation.NonNull;
import com.bumptech.glide.load.Options;
import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.data.FileDescriptorAssetPathFetcher;
@@ -33,14 +34,14 @@ public AssetUriLoader(AssetManager assetManager, AssetFetcherFactory facto
}
@Override
- public LoadData buildLoadData(Uri model, int width, int height,
- Options options) {
+ public LoadData buildLoadData(@NonNull Uri model, int width, int height,
+ @NonNull Options options) {
String assetPath = model.toString().substring(ASSET_PREFIX_LENGTH);
return new LoadData<>(new ObjectKey(model), factory.buildFetcher(assetManager, assetPath));
}
@Override
- public boolean handles(Uri model) {
+ public boolean handles(@NonNull Uri model) {
return ContentResolver.SCHEME_FILE.equals(model.getScheme()) && !model.getPathSegments()
.isEmpty() && ASSET_PATH_SEGMENT.equals(model.getPathSegments().get(0));
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java b/library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java
index c0264e40ba..54d80326ce 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java
@@ -28,12 +28,12 @@ public ByteArrayLoader(Converter converter) {
@Override
public LoadData buildLoadData(
- byte[] model, int width, int height, Options options) {
+ @NonNull byte[] model, int width, int height, @NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new Fetcher<>(model, converter));
}
@Override
- public boolean handles(byte[] model) {
+ public boolean handles(@NonNull byte[] model) {
return true;
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java b/library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java
index db442bc83f..bc0ac5dc5d 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java
@@ -20,13 +20,13 @@ public class ByteBufferFileLoader implements ModelLoader {
private static final String TAG = "ByteBufferFileLoader";
@Override
- public LoadData buildLoadData(File file, int width, int height,
- Options options) {
+ public LoadData buildLoadData(@NonNull File file, int width, int height,
+ @NonNull Options options) {
return new LoadData<>(new ObjectKey(file), new ByteBufferFetcher(file));
}
@Override
- public boolean handles(File file) {
+ public boolean handles(@NonNull File file) {
return true;
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java b/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java
index 436f251e0c..8a47e2068e 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java
@@ -35,12 +35,13 @@ public DataUrlLoader(DataDecoder dataDecoder) {
}
@Override
- public LoadData buildLoadData(String model, int width, int height, Options options) {
+ public LoadData buildLoadData(@NonNull String model, int width, int height,
+ @NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new DataUriFetcher<>(model, dataDecoder));
}
@Override
- public boolean handles(String url) {
+ public boolean handles(@NonNull String url) {
return url.startsWith(DATA_SCHEME_IMAGE);
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/FileLoader.java b/library/src/main/java/com/bumptech/glide/load/model/FileLoader.java
index 7d83eba058..0e1b732b2f 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/FileLoader.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/FileLoader.java
@@ -32,13 +32,13 @@ public FileLoader(FileOpener fileOpener) {
}
@Override
- public LoadData buildLoadData(File model, int width, int height,
- Options options) {
+ public LoadData buildLoadData(@NonNull File model, int width, int height,
+ @NonNull Options options) {
return new LoadData<>(new ObjectKey(model), new FileFetcher<>(model, fileOpener));
}
@Override
- public boolean handles(File model) {
+ public boolean handles(@NonNull File model) {
return true;
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java b/library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java
index d4cd56d7f2..32867b9283 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java
@@ -18,7 +18,7 @@
/**
* Loads the file path for {@link MediaStore} owned {@link Uri uris}.
*/
-public final class MediaStoreFileLoader implements ModelLoader {
+public final class MediaStoreFileLoader implements ModelLoader {
private final Context context;
@@ -29,12 +29,13 @@ public MediaStoreFileLoader(Context context) {
}
@Override
- public LoadData buildLoadData(Uri uri, int width, int height, Options options) {
+ public LoadData buildLoadData(@NonNull Uri uri, int width, int height,
+ @NonNull Options options) {
return new LoadData<>(new ObjectKey(uri), new FilePathFetcher(context, uri));
}
@Override
- public boolean handles(Uri uri) {
+ public boolean handles(@NonNull Uri uri) {
return MediaStoreUtil.isMediaStoreUri(uri);
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java b/library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java
index 230551c5df..30fde57fd8 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.model;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.Options;
@@ -77,7 +78,8 @@ public LoadData(Key sourceKey, List alternateKeys, DataFetcher fetche
* the resource should be loaded at its original height.
*/
@Nullable
- LoadData buildLoadData(Model model, int width, int height, Options options);
+ LoadData buildLoadData(@NonNull Model model, int width, int height,
+ @NonNull Options options);
/**
* Returns true if the given model is a of a recognized type that this loader can probably load.
@@ -89,5 +91,5 @@ public LoadData(Key sourceKey, List alternateKeys, DataFetcher fetche
* results are acceptable. {@link ModelLoader ModelLoaders} that return true from this method may
* return {@code null} from {@link #buildLoadData(Object, int, int, Options)}
*/
- boolean handles(Model model);
+ boolean handles(@NonNull Model model);
}
diff --git a/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java b/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java
index 316ee755e1..d77abaa5ee 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java
@@ -36,8 +36,8 @@ class MultiModelLoader implements ModelLoader {
}
@Override
- public LoadData buildLoadData(Model model, int width, int height,
- Options options) {
+ public LoadData buildLoadData(@NonNull Model model, int width, int height,
+ @NonNull Options options) {
Key sourceKey = null;
int size = modelLoaders.size();
List> fetchers = new ArrayList<>(size);
@@ -56,7 +56,7 @@ public LoadData buildLoadData(Model model, int width, int height,
}
@Override
- public boolean handles(Model model) {
+ public boolean handles(@NonNull Model model) {
for (ModelLoader modelLoader : modelLoaders) {
if (modelLoader.handles(model)) {
return true;
diff --git a/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java b/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java
index c5ac002667..eb903fab35 100644
--- a/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java
+++ b/library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java
@@ -1,5 +1,6 @@
package com.bumptech.glide.load.model;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.v4.util.Pools.Pool;
@@ -213,12 +214,13 @@ private static class EmptyModelLoader implements ModelLoader