Skip to content

Commit c3dafde

Browse files
SUPERCILEXsjudd
authored andcommitted
Add nullability annotations to okhttp3 module and its dependencies (#2685)
* Add nullability annotations to okhttp3 module and its dependencies Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
1 parent dc12b60 commit c3dafde

33 files changed

+113
-70
lines changed

integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpLibraryGlideModule.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bumptech.glide.integration.okhttp3;
22

33
import android.content.Context;
4+
import android.support.annotation.NonNull;
45
import com.bumptech.glide.Glide;
56
import com.bumptech.glide.Registry;
67
import com.bumptech.glide.annotation.GlideModule;
@@ -19,7 +20,8 @@
1920
@GlideModule
2021
public final class OkHttpLibraryGlideModule extends LibraryGlideModule {
2122
@Override
22-
public void registerComponents(Context context, Glide glide, Registry registry) {
23+
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
24+
@NonNull Registry registry) {
2325
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory());
2426
}
2527
}

integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpStreamFetcher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) {
7777
}
7878

7979
@Override
80-
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
80+
public void onResponse(@NonNull Call call, @NonNull Response response) {
8181
responseBody = response.body();
8282
if (response.isSuccessful()) {
8383
long contentLength = Preconditions.checkNotNull(responseBody).contentLength();

integration/okhttp3/src/main/java/com/bumptech/glide/integration/okhttp3/OkHttpUrlLoader.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.integration.okhttp3;
22

3+
import android.support.annotation.NonNull;
34
import com.bumptech.glide.load.Options;
45
import com.bumptech.glide.load.model.GlideUrl;
56
import com.bumptech.glide.load.model.ModelLoader;
@@ -18,18 +19,18 @@ public class OkHttpUrlLoader implements ModelLoader<GlideUrl, InputStream> {
1819

1920
// Public API.
2021
@SuppressWarnings("WeakerAccess")
21-
public OkHttpUrlLoader(Call.Factory client) {
22+
public OkHttpUrlLoader(@NonNull Call.Factory client) {
2223
this.client = client;
2324
}
2425

2526
@Override
26-
public boolean handles(GlideUrl url) {
27+
public boolean handles(@NonNull GlideUrl url) {
2728
return true;
2829
}
2930

3031
@Override
31-
public LoadData<InputStream> buildLoadData(GlideUrl model, int width, int height,
32-
Options options) {
32+
public LoadData<InputStream> buildLoadData(@NonNull GlideUrl model, int width, int height,
33+
@NonNull Options options) {
3334
return new LoadData<>(model, new OkHttpStreamFetcher(client, model));
3435
}
3536

@@ -65,10 +66,11 @@ public Factory() {
6566
*
6667
* @param client this is typically an instance of {@code OkHttpClient}.
6768
*/
68-
public Factory(Call.Factory client) {
69+
public Factory(@NonNull Call.Factory client) {
6970
this.client = client;
7071
}
7172

73+
@NonNull
7274
@Override
7375
public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) {
7476
return new OkHttpUrlLoader(client);

integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyLibraryGlideModule.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bumptech.glide.integration.volley;
22

33
import android.content.Context;
4+
import android.support.annotation.NonNull;
45
import com.bumptech.glide.Glide;
56
import com.bumptech.glide.Registry;
67
import com.bumptech.glide.annotation.GlideModule;
@@ -21,7 +22,8 @@
2122
@GlideModule
2223
public class VolleyLibraryGlideModule extends LibraryGlideModule {
2324
@Override
24-
public void registerComponents(Context context, Glide glide, Registry registry) {
25+
public void registerComponents(@NonNull Context context, @NonNull Glide glide,
26+
@NonNull Registry registry) {
2527
registry.replace(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(context));
2628
}
2729
}

integration/volley/src/main/java/com/bumptech/glide/integration/volley/VolleyUrlLoader.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bumptech.glide.integration.volley;
22

33
import android.content.Context;
4+
import android.support.annotation.NonNull;
45
import com.android.volley.RequestQueue;
56
import com.android.volley.toolbox.Volley;
67
import com.bumptech.glide.load.Options;
@@ -32,13 +33,13 @@ public VolleyUrlLoader(RequestQueue requestQueue, VolleyRequestFactory requestFa
3233
}
3334

3435
@Override
35-
public boolean handles(GlideUrl url) {
36+
public boolean handles(@NonNull GlideUrl url) {
3637
return true;
3738
}
3839

3940
@Override
40-
public LoadData<InputStream> buildLoadData(GlideUrl url, int width, int height,
41-
Options options) {
41+
public LoadData<InputStream> buildLoadData(@NonNull GlideUrl url, int width, int height,
42+
@NonNull Options options) {
4243
return new LoadData<>(url, new VolleyStreamFetcher(requestQueue, url, requestFactory));
4344
}
4445

library/src/main/java/com/bumptech/glide/load/model/AssetUriLoader.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.res.AssetManager;
55
import android.net.Uri;
66
import android.os.ParcelFileDescriptor;
7+
import android.support.annotation.NonNull;
78
import com.bumptech.glide.load.Options;
89
import com.bumptech.glide.load.data.DataFetcher;
910
import com.bumptech.glide.load.data.FileDescriptorAssetPathFetcher;
@@ -33,14 +34,14 @@ public AssetUriLoader(AssetManager assetManager, AssetFetcherFactory<Data> facto
3334
}
3435

3536
@Override
36-
public LoadData<Data> buildLoadData(Uri model, int width, int height,
37-
Options options) {
37+
public LoadData<Data> buildLoadData(@NonNull Uri model, int width, int height,
38+
@NonNull Options options) {
3839
String assetPath = model.toString().substring(ASSET_PREFIX_LENGTH);
3940
return new LoadData<>(new ObjectKey(model), factory.buildFetcher(assetManager, assetPath));
4041
}
4142

4243
@Override
43-
public boolean handles(Uri model) {
44+
public boolean handles(@NonNull Uri model) {
4445
return ContentResolver.SCHEME_FILE.equals(model.getScheme()) && !model.getPathSegments()
4546
.isEmpty() && ASSET_PATH_SEGMENT.equals(model.getPathSegments().get(0));
4647
}

library/src/main/java/com/bumptech/glide/load/model/ByteArrayLoader.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public ByteArrayLoader(Converter<Data> converter) {
2828

2929
@Override
3030
public LoadData<Data> buildLoadData(
31-
byte[] model, int width, int height, Options options) {
31+
@NonNull byte[] model, int width, int height, @NonNull Options options) {
3232
return new LoadData<>(new ObjectKey(model), new Fetcher<>(model, converter));
3333
}
3434

3535
@Override
36-
public boolean handles(byte[] model) {
36+
public boolean handles(@NonNull byte[] model) {
3737
return true;
3838
}
3939

library/src/main/java/com/bumptech/glide/load/model/ByteBufferFileLoader.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public class ByteBufferFileLoader implements ModelLoader<File, ByteBuffer> {
2020
private static final String TAG = "ByteBufferFileLoader";
2121

2222
@Override
23-
public LoadData<ByteBuffer> buildLoadData(File file, int width, int height,
24-
Options options) {
23+
public LoadData<ByteBuffer> buildLoadData(@NonNull File file, int width, int height,
24+
@NonNull Options options) {
2525
return new LoadData<>(new ObjectKey(file), new ByteBufferFetcher(file));
2626
}
2727

2828
@Override
29-
public boolean handles(File file) {
29+
public boolean handles(@NonNull File file) {
3030
return true;
3131
}
3232

library/src/main/java/com/bumptech/glide/load/model/DataUrlLoader.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ public DataUrlLoader(DataDecoder<Data> dataDecoder) {
3535
}
3636

3737
@Override
38-
public LoadData<Data> buildLoadData(String model, int width, int height, Options options) {
38+
public LoadData<Data> buildLoadData(@NonNull String model, int width, int height,
39+
@NonNull Options options) {
3940
return new LoadData<>(new ObjectKey(model), new DataUriFetcher<>(model, dataDecoder));
4041
}
4142

4243
@Override
43-
public boolean handles(String url) {
44+
public boolean handles(@NonNull String url) {
4445
return url.startsWith(DATA_SCHEME_IMAGE);
4546
}
4647

library/src/main/java/com/bumptech/glide/load/model/FileLoader.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public FileLoader(FileOpener<Data> fileOpener) {
3232
}
3333

3434
@Override
35-
public LoadData<Data> buildLoadData(File model, int width, int height,
36-
Options options) {
35+
public LoadData<Data> buildLoadData(@NonNull File model, int width, int height,
36+
@NonNull Options options) {
3737
return new LoadData<>(new ObjectKey(model), new FileFetcher<>(model, fileOpener));
3838
}
3939

4040
@Override
41-
public boolean handles(File model) {
41+
public boolean handles(@NonNull File model) {
4242
return true;
4343
}
4444

library/src/main/java/com/bumptech/glide/load/model/MediaStoreFileLoader.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Loads the file path for {@link MediaStore} owned {@link Uri uris}.
2020
*/
21-
public final class MediaStoreFileLoader implements ModelLoader<Uri, File> {
21+
public final class MediaStoreFileLoader implements ModelLoader<Uri, File> {
2222

2323
private final Context context;
2424

@@ -29,12 +29,13 @@ public MediaStoreFileLoader(Context context) {
2929
}
3030

3131
@Override
32-
public LoadData<File> buildLoadData(Uri uri, int width, int height, Options options) {
32+
public LoadData<File> buildLoadData(@NonNull Uri uri, int width, int height,
33+
@NonNull Options options) {
3334
return new LoadData<>(new ObjectKey(uri), new FilePathFetcher(context, uri));
3435
}
3536

3637
@Override
37-
public boolean handles(Uri uri) {
38+
public boolean handles(@NonNull Uri uri) {
3839
return MediaStoreUtil.isMediaStoreUri(uri);
3940
}
4041

library/src/main/java/com/bumptech/glide/load/model/ModelLoader.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.load.model;
22

3+
import android.support.annotation.NonNull;
34
import android.support.annotation.Nullable;
45
import com.bumptech.glide.load.Key;
56
import com.bumptech.glide.load.Options;
@@ -77,7 +78,8 @@ public LoadData(Key sourceKey, List<Key> alternateKeys, DataFetcher<Data> fetche
7778
* the resource should be loaded at its original height.
7879
*/
7980
@Nullable
80-
LoadData<Data> buildLoadData(Model model, int width, int height, Options options);
81+
LoadData<Data> buildLoadData(@NonNull Model model, int width, int height,
82+
@NonNull Options options);
8183

8284
/**
8385
* 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<Key> alternateKeys, DataFetcher<Data> fetche
8991
* results are acceptable. {@link ModelLoader ModelLoaders} that return true from this method may
9092
* return {@code null} from {@link #buildLoadData(Object, int, int, Options)} </p>
9193
*/
92-
boolean handles(Model model);
94+
boolean handles(@NonNull Model model);
9395
}

library/src/main/java/com/bumptech/glide/load/model/MultiModelLoader.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class MultiModelLoader<Model, Data> implements ModelLoader<Model, Data> {
3636
}
3737

3838
@Override
39-
public LoadData<Data> buildLoadData(Model model, int width, int height,
40-
Options options) {
39+
public LoadData<Data> buildLoadData(@NonNull Model model, int width, int height,
40+
@NonNull Options options) {
4141
Key sourceKey = null;
4242
int size = modelLoaders.size();
4343
List<DataFetcher<Data>> fetchers = new ArrayList<>(size);
@@ -56,7 +56,7 @@ public LoadData<Data> buildLoadData(Model model, int width, int height,
5656
}
5757

5858
@Override
59-
public boolean handles(Model model) {
59+
public boolean handles(@NonNull Model model) {
6060
for (ModelLoader<Model, Data> modelLoader : modelLoaders) {
6161
if (modelLoader.handles(model)) {
6262
return true;

library/src/main/java/com/bumptech/glide/load/model/MultiModelLoaderFactory.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.bumptech.glide.load.model;
22

3+
import android.support.annotation.NonNull;
34
import android.support.annotation.Nullable;
45
import android.support.annotation.VisibleForTesting;
56
import android.support.v4.util.Pools.Pool;
@@ -213,12 +214,13 @@ private static class EmptyModelLoader implements ModelLoader<Object, Object> {
213214

214215
@Nullable
215216
@Override
216-
public LoadData<Object> buildLoadData(Object o, int width, int height, Options options) {
217+
public LoadData<Object> buildLoadData(@NonNull Object o, int width, int height,
218+
@NonNull Options options) {
217219
return null;
218220
}
219221

220222
@Override
221-
public boolean handles(Object o) {
223+
public boolean handles(@NonNull Object o) {
222224
return false;
223225
}
224226
}

library/src/main/java/com/bumptech/glide/load/model/ResourceLoader.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.res.Resources;
55
import android.net.Uri;
66
import android.os.ParcelFileDescriptor;
7+
import android.support.annotation.NonNull;
78
import android.support.annotation.Nullable;
89
import android.util.Log;
910
import com.bumptech.glide.load.Options;
@@ -28,7 +29,8 @@ public ResourceLoader(Resources resources, ModelLoader<Uri, Data> uriLoader) {
2829
}
2930

3031
@Override
31-
public LoadData<Data> buildLoadData(Integer model, int width, int height, Options options) {
32+
public LoadData<Data> buildLoadData(@NonNull Integer model, int width, int height,
33+
@NonNull Options options) {
3234
Uri uri = getResourceUri(model);
3335
return uri == null ? null : uriLoader.buildLoadData(uri, width, height, options);
3436
}
@@ -49,7 +51,7 @@ private Uri getResourceUri(Integer model) {
4951
}
5052

5153
@Override
52-
public boolean handles(Integer model) {
54+
public boolean handles(@NonNull Integer model) {
5355
// TODO: check that this is in fact a resource id.
5456
return true;
5557
}

library/src/main/java/com/bumptech/glide/load/model/StringLoader.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.net.Uri;
44
import android.os.ParcelFileDescriptor;
5+
import android.support.annotation.NonNull;
56
import android.support.annotation.Nullable;
67
import android.text.TextUtils;
78
import com.bumptech.glide.load.Options;
@@ -24,14 +25,14 @@ public StringLoader(ModelLoader<Uri, Data> uriLoader) {
2425
}
2526

2627
@Override
27-
public LoadData<Data> buildLoadData(String model, int width, int height,
28-
Options options) {
28+
public LoadData<Data> buildLoadData(@NonNull String model, int width, int height,
29+
@NonNull Options options) {
2930
Uri uri = parseUri(model);
3031
return uri == null ? null : uriLoader.buildLoadData(uri, width, height, options);
3132
}
3233

3334
@Override
34-
public boolean handles(String model) {
35+
public boolean handles(@NonNull String model) {
3536
return true;
3637
}
3738

library/src/main/java/com/bumptech/glide/load/model/UnitModelLoader.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public UnitModelLoader() {
3131
}
3232

3333
@Override
34-
public LoadData<Model> buildLoadData(Model model, int width, int height,
35-
Options options) {
34+
public LoadData<Model> buildLoadData(@NonNull Model model, int width, int height,
35+
@NonNull Options options) {
3636
return new LoadData<>(new ObjectKey(model), new UnitFetcher<>(model));
3737
}
3838

3939
@Override
40-
public boolean handles(Model model) {
40+
public boolean handles(@NonNull Model model) {
4141
return true;
4242
}
4343

library/src/main/java/com/bumptech/glide/load/model/UriLoader.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.ContentResolver;
44
import android.net.Uri;
55
import android.os.ParcelFileDescriptor;
6+
import android.support.annotation.NonNull;
67
import com.bumptech.glide.load.Options;
78
import com.bumptech.glide.load.data.DataFetcher;
89
import com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher;
@@ -42,13 +43,13 @@ public UriLoader(LocalUriFetcherFactory<Data> factory) {
4243
}
4344

4445
@Override
45-
public LoadData<Data> buildLoadData(Uri model, int width, int height,
46-
Options options) {
46+
public LoadData<Data> buildLoadData(@NonNull Uri model, int width, int height,
47+
@NonNull Options options) {
4748
return new LoadData<>(new ObjectKey(model), factory.build(model));
4849
}
4950

5051
@Override
51-
public boolean handles(Uri model) {
52+
public boolean handles(@NonNull Uri model) {
5253
return SCHEMES.contains(model.getScheme());
5354
}
5455

0 commit comments

Comments
 (0)