From f541b65e596a49d252ba6b80d3b05a111ce93461 Mon Sep 17 00:00:00 2001
From: Alex Saveau <saveau.alexandre@gmail.com>
Date: Thu, 14 Dec 2017 11:59:41 -0800
Subject: [PATCH] Add nullability annotations to gif modules (#2712)

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
---
 .../bumptech/glide/load/ResourceDecoder.java  |  6 ++-
 .../glide/load/engine/EngineResource.java     |  3 ++
 .../glide/load/engine/LockedResource.java     |  3 ++
 .../bumptech/glide/load/engine/Resource.java  |  3 ++
 .../glide/load/resource/SimpleResource.java   |  3 ++
 .../bitmap/BitmapDrawableDecoder.java         |  5 ++-
 .../bitmap/BitmapDrawableResource.java        |  2 +
 .../load/resource/bitmap/BitmapResource.java  |  7 +++-
 .../bitmap/ByteBufferBitmapDecoder.java       |  6 ++-
 .../bitmap/LazyBitmapDrawableResource.java    |  2 +
 .../bitmap/ResourceBitmapDecoder.java         |  8 ++--
 .../resource/bitmap/StreamBitmapDecoder.java  |  6 ++-
 .../resource/bitmap/UnitBitmapDecoder.java    | 12 +++---
 .../resource/bitmap/VideoBitmapDecoder.java   | 11 ++++--
 .../load/resource/bytes/BytesResource.java    |  3 ++
 .../resource/drawable/DrawableResource.java   |  2 +
 .../drawable/NonOwnedDrawableResource.java    |  2 +
 .../drawable/ResourceDrawableDecoder.java     | 39 +++++++++----------
 .../drawable/UnitDrawableDecoder.java         |  8 ++--
 .../glide/load/resource/file/FileDecoder.java |  6 ++-
 .../resource/gif/ByteBufferGifDecoder.java    |  8 +++-
 .../load/resource/gif/GifBitmapProvider.java  | 10 +++--
 .../resource/gif/GifDrawableResource.java     |  4 +-
 .../resource/gif/GifFrameResourceDecoder.java |  6 ++-
 .../load/resource/gif/StreamGifDecoder.java   |  7 ++--
 .../drawable/DrawableResourceTest.java        |  2 +
 .../glide/samples/svg/SvgDecoder.java         |  6 ++-
 .../bumptech/glide/gifdecoder/GifDecoder.java | 25 +++++++-----
 .../glide/gifdecoder/GifHeaderParser.java     |  8 +++-
 .../glide/gifdecoder/StandardGifDecoder.java  | 24 +++++++-----
 .../glide/gifdecoder/GifDecoderTest.java      |  8 ++--
 .../glide/gifencoder/AnimatedGifEncoder.java  | 12 +++---
 32 files changed, 164 insertions(+), 93 deletions(-)

diff --git a/library/src/main/java/com/bumptech/glide/load/ResourceDecoder.java b/library/src/main/java/com/bumptech/glide/load/ResourceDecoder.java
index c6c3affbba..977339e253 100644
--- a/library/src/main/java/com/bumptech/glide/load/ResourceDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/ResourceDecoder.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.load;
 
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import com.bumptech.glide.load.engine.Resource;
 import java.io.IOException;
@@ -24,7 +25,7 @@ public interface ResourceDecoder<T, Z> {
    * <p>Decoders that return {@code true} from {@code handles} may still return {@code null} from
    * {@link #decode(Object, int, int, Options)} if the data is partial or formatted incorrectly.
    */
-  boolean handles(T source, Options options) throws IOException;
+  boolean handles(@NonNull T source, @NonNull Options options) throws IOException;
 
   /**
    * Returns a decoded resource from the given data or null if no resource could be decoded.
@@ -51,5 +52,6 @@ public interface ResourceDecoder<T, Z> {
    *                expected type.
    */
   @Nullable
-  Resource<Z> decode(T source, int width, int height, Options options) throws IOException;
+  Resource<Z> decode(@NonNull T source, int width, int height, @NonNull Options options)
+      throws IOException;
 }
diff --git a/library/src/main/java/com/bumptech/glide/load/engine/EngineResource.java b/library/src/main/java/com/bumptech/glide/load/engine/EngineResource.java
index 51cf1f8247..75bb1b8412 100644
--- a/library/src/main/java/com/bumptech/glide/load/engine/EngineResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/engine/EngineResource.java
@@ -1,6 +1,7 @@
 package com.bumptech.glide.load.engine;
 
 import android.os.Looper;
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.Key;
 import com.bumptech.glide.util.Preconditions;
 
@@ -42,11 +43,13 @@ boolean isCacheable() {
     return isCacheable;
   }
 
+  @NonNull
   @Override
   public Class<Z> getResourceClass() {
     return resource.getResourceClass();
   }
 
+  @NonNull
   @Override
   public Z get() {
     return resource.get();
diff --git a/library/src/main/java/com/bumptech/glide/load/engine/LockedResource.java b/library/src/main/java/com/bumptech/glide/load/engine/LockedResource.java
index 164161f72f..7770829c6d 100644
--- a/library/src/main/java/com/bumptech/glide/load/engine/LockedResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/engine/LockedResource.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.load.engine;
 
+import android.support.annotation.NonNull;
 import android.support.v4.util.Pools;
 import com.bumptech.glide.util.Preconditions;
 import com.bumptech.glide.util.Synthetic;
@@ -61,11 +62,13 @@ synchronized void unlock() {
     }
   }
 
+  @NonNull
   @Override
   public Class<Z> getResourceClass() {
     return toWrap.getResourceClass();
   }
 
+  @NonNull
   @Override
   public Z get() {
     return toWrap.get();
diff --git a/library/src/main/java/com/bumptech/glide/load/engine/Resource.java b/library/src/main/java/com/bumptech/glide/load/engine/Resource.java
index 3717a889df..6667381baf 100644
--- a/library/src/main/java/com/bumptech/glide/load/engine/Resource.java
+++ b/library/src/main/java/com/bumptech/glide/load/engine/Resource.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.load.engine;
 
+import android.support.annotation.NonNull;
 
 /**
  * A resource interface that wraps a particular type so that it can be pooled and reused.
@@ -11,6 +12,7 @@ public interface Resource<Z> {
   /**
    * Returns the {@link Class} of the wrapped resource.
    */
+  @NonNull
   Class<Z> getResourceClass();
 
   /**
@@ -23,6 +25,7 @@ public interface Resource<Z> {
    * {@link android.graphics.drawable.Drawable Drawable}s should always return a new
    * {@link android.graphics.drawable.Drawable Drawable}. </p>
    */
+  @NonNull
   Z get();
 
   /**
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/SimpleResource.java b/library/src/main/java/com/bumptech/glide/load/resource/SimpleResource.java
index 5291061e07..1ee1ac609b 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/SimpleResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/SimpleResource.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.load.resource;
 
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.engine.Resource;
 import com.bumptech.glide.util.Preconditions;
 
@@ -18,12 +19,14 @@ public SimpleResource(T data) {
     this.data = Preconditions.checkNotNull(data);
   }
 
+  @NonNull
   @SuppressWarnings("unchecked")
   @Override
   public Class<T> getResourceClass() {
     return (Class<T>) data.getClass();
   }
 
+  @NonNull
   @Override
   public final T get() {
     return data;
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableDecoder.java
index e9b954c4ad..40a2d4c925 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableDecoder.java
@@ -47,12 +47,13 @@ public BitmapDrawableDecoder(
   }
 
   @Override
-  public boolean handles(DataType source, Options options) throws IOException {
+  public boolean handles(@NonNull DataType source, @NonNull Options options) throws IOException {
     return decoder.handles(source, options);
   }
 
   @Override
-  public Resource<BitmapDrawable> decode(DataType source, int width, int height, Options options)
+  public Resource<BitmapDrawable> decode(@NonNull DataType source, int width, int height,
+      @NonNull Options options)
       throws IOException {
     Resource<Bitmap> bitmapResource = decoder.decode(source, width, height, options);
     return LazyBitmapDrawableResource.obtain(resources, bitmapResource);
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableResource.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableResource.java
index d8c1e048c0..736c02ea63 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableResource.java
@@ -1,6 +1,7 @@
 package com.bumptech.glide.load.resource.bitmap;
 
 import android.graphics.drawable.BitmapDrawable;
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.engine.Initializable;
 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
 import com.bumptech.glide.load.resource.drawable.DrawableResource;
@@ -27,6 +28,7 @@ public BitmapDrawableResource(BitmapDrawable drawable, BitmapPool bitmapPool) {
     this.bitmapPool = bitmapPool;
   }
 
+  @NonNull
   @Override
   public Class<BitmapDrawable> getResourceClass() {
     return BitmapDrawable.class;
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapResource.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapResource.java
index 102c688c0b..49e57a956e 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapResource.java
@@ -1,6 +1,7 @@
 package com.bumptech.glide.load.resource.bitmap;
 
 import android.graphics.Bitmap;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import com.bumptech.glide.load.engine.Initializable;
 import com.bumptech.glide.load.engine.Resource;
@@ -24,7 +25,7 @@ public class BitmapResource implements Resource<Bitmap>,
    * @param bitmapPool A non-null {@link com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool}.
    */
   @Nullable
-  public static BitmapResource obtain(@Nullable Bitmap bitmap, BitmapPool bitmapPool) {
+  public static BitmapResource obtain(@Nullable Bitmap bitmap, @NonNull BitmapPool bitmapPool) {
     if (bitmap == null) {
       return null;
     } else {
@@ -32,16 +33,18 @@ public static BitmapResource obtain(@Nullable Bitmap bitmap, BitmapPool bitmapPo
     }
   }
 
-  public BitmapResource(Bitmap bitmap, BitmapPool bitmapPool) {
+  public BitmapResource(@NonNull Bitmap bitmap, @NonNull BitmapPool bitmapPool) {
     this.bitmap = Preconditions.checkNotNull(bitmap, "Bitmap must not be null");
     this.bitmapPool = Preconditions.checkNotNull(bitmapPool, "BitmapPool must not be null");
   }
 
+  @NonNull
   @Override
   public Class<Bitmap> getResourceClass() {
     return Bitmap.class;
   }
 
+  @NonNull
   @Override
   public Bitmap get() {
     return bitmap;
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ByteBufferBitmapDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ByteBufferBitmapDecoder.java
index 6a6c9ec8fb..97084a0252 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ByteBufferBitmapDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ByteBufferBitmapDecoder.java
@@ -1,6 +1,7 @@
 package com.bumptech.glide.load.resource.bitmap;
 
 import android.graphics.Bitmap;
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
 import com.bumptech.glide.load.engine.Resource;
@@ -20,12 +21,13 @@ public ByteBufferBitmapDecoder(Downsampler downsampler) {
   }
 
   @Override
-  public boolean handles(ByteBuffer source, Options options) throws IOException {
+  public boolean handles(@NonNull ByteBuffer source, @NonNull Options options) {
     return downsampler.handles(source);
   }
 
   @Override
-  public Resource<Bitmap> decode(ByteBuffer source, int width, int height, Options options)
+  public Resource<Bitmap> decode(@NonNull ByteBuffer source, int width, int height,
+      @NonNull Options options)
       throws IOException {
     InputStream is = ByteBufferUtil.toStream(source);
     return downsampler.decode(is, width, height, options);
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/LazyBitmapDrawableResource.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/LazyBitmapDrawableResource.java
index 42058fca85..ae2ef225dc 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/LazyBitmapDrawableResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/LazyBitmapDrawableResource.java
@@ -61,11 +61,13 @@ private LazyBitmapDrawableResource(Resources resources, Resource<Bitmap> bitmapR
     this.bitmapResource = Preconditions.checkNotNull(bitmapResource);
   }
 
+  @NonNull
   @Override
   public Class<BitmapDrawable> getResourceClass() {
     return BitmapDrawable.class;
   }
 
+  @NonNull
   @Override
   public BitmapDrawable get() {
     return new BitmapDrawable(resources, bitmapResource.get());
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ResourceBitmapDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ResourceBitmapDecoder.java
index df92c3d481..e888fd5c19 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ResourceBitmapDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/ResourceBitmapDecoder.java
@@ -5,6 +5,7 @@
 import android.graphics.Canvas;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
@@ -12,7 +13,6 @@
 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
 import com.bumptech.glide.load.resource.drawable.ResourceDrawableDecoder;
 import com.bumptech.glide.request.target.Target;
-import java.io.IOException;
 
 /**
  * Decodes {@link Bitmap}s from resource ids.
@@ -39,14 +39,14 @@ public ResourceBitmapDecoder(ResourceDrawableDecoder drawableDecoder, BitmapPool
   }
 
   @Override
-  public boolean handles(Uri source, Options options) throws IOException {
+  public boolean handles(@NonNull Uri source, @NonNull Options options) {
     return ContentResolver.SCHEME_ANDROID_RESOURCE.equals(source.getScheme());
   }
 
   @Nullable
   @Override
-  public Resource<Bitmap> decode(Uri source, int width, int height, Options options)
-      throws IOException {
+  public Resource<Bitmap> decode(@NonNull Uri source, int width, int height,
+      @NonNull Options options) {
     Resource<Drawable> drawableResource = drawableDecoder.decode(source, width, height, options);
     Drawable drawable = drawableResource.get();
     return DrawableToBitmapConverter.convert(bitmapPool, drawable, width, height);
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/StreamBitmapDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/StreamBitmapDecoder.java
index a744becf94..00cc6f3c12 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/StreamBitmapDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/StreamBitmapDecoder.java
@@ -1,6 +1,7 @@
 package com.bumptech.glide.load.resource.bitmap;
 
 import android.graphics.Bitmap;
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
 import com.bumptech.glide.load.engine.Resource;
@@ -25,12 +26,13 @@ public StreamBitmapDecoder(Downsampler downsampler, ArrayPool byteArrayPool) {
   }
 
   @Override
-  public boolean handles(InputStream source, Options options) throws IOException {
+  public boolean handles(@NonNull InputStream source, @NonNull Options options) {
     return downsampler.handles(source);
   }
 
   @Override
-  public Resource<Bitmap> decode(InputStream source, int width, int height, Options options)
+  public Resource<Bitmap> decode(@NonNull InputStream source, int width, int height,
+      @NonNull Options options)
       throws IOException {
 
     // Use to fix the mark limit to avoid allocating buffers that fit entire images.
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/UnitBitmapDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/UnitBitmapDecoder.java
index 2b91d20812..63e804bb1a 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/UnitBitmapDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/UnitBitmapDecoder.java
@@ -1,11 +1,11 @@
 package com.bumptech.glide.load.resource.bitmap;
 
 import android.graphics.Bitmap;
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
 import com.bumptech.glide.load.engine.Resource;
 import com.bumptech.glide.util.Util;
-import java.io.IOException;
 
 /**
  * Passes through a (hopefully) non-owned {@link Bitmap} as a {@link Bitmap} based {@link Resource}
@@ -14,13 +14,13 @@
 public final class UnitBitmapDecoder implements ResourceDecoder<Bitmap, Bitmap> {
 
   @Override
-  public boolean handles(Bitmap source, Options options) throws IOException {
+  public boolean handles(@NonNull Bitmap source, @NonNull Options options) {
     return true;
   }
 
   @Override
-  public Resource<Bitmap> decode(Bitmap source, int width, int height, Options options)
-      throws IOException {
+  public Resource<Bitmap> decode(@NonNull Bitmap source, int width, int height,
+      @NonNull Options options) {
     return new NonOwnedBitmapResource(source);
   }
 
@@ -28,15 +28,17 @@ private static final class NonOwnedBitmapResource implements Resource<Bitmap> {
 
     private final Bitmap bitmap;
 
-    NonOwnedBitmapResource(Bitmap bitmap) {
+    NonOwnedBitmapResource(@NonNull Bitmap bitmap) {
       this.bitmap = bitmap;
     }
 
+    @NonNull
     @Override
     public Class<Bitmap> getResourceClass() {
       return Bitmap.class;
     }
 
+    @NonNull
     @Override
     public Bitmap get() {
       return bitmap;
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoBitmapDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoBitmapDecoder.java
index c24d500c55..ce47e2f6bd 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoBitmapDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoBitmapDecoder.java
@@ -4,6 +4,7 @@
 import android.graphics.Bitmap;
 import android.media.MediaMetadataRetriever;
 import android.os.ParcelFileDescriptor;
+import android.support.annotation.NonNull;
 import android.support.annotation.VisibleForTesting;
 import com.bumptech.glide.Glide;
 import com.bumptech.glide.load.Option;
@@ -43,6 +44,7 @@ public class VideoBitmapDecoder implements ResourceDecoder<ParcelFileDescriptor,
       "com.bumptech.glide.load.resource.bitmap.VideoBitmapDecode.TargetFrame", DEFAULT_FRAME,
       new Option.CacheKeyUpdater<Long>() {
         private final ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE);
+
         @Override
         public void update(byte[] keyBytes, Long value, MessageDigest messageDigest) {
           messageDigest.update(keyBytes);
@@ -68,6 +70,7 @@ public void update(byte[] keyBytes, Long value, MessageDigest messageDigest) {
       null /*defaultValue*/,
       new Option.CacheKeyUpdater<Integer>() {
         private final ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
+
         @Override
         public void update(byte[] keyBytes, Integer value, MessageDigest messageDigest) {
           if (value == null) {
@@ -105,16 +108,16 @@ public VideoBitmapDecoder(BitmapPool bitmapPool) {
   }
 
   @Override
-  public boolean handles(ParcelFileDescriptor data, Options options) {
+  public boolean handles(@NonNull ParcelFileDescriptor data, @NonNull Options options) {
     // Calling setDataSource is expensive so avoid doing so unless we're actually called.
-    // For non-videos this isn't any cheaper, but for videos it safes the redundant call and
+    // For non-videos this isn't any cheaper, but for videos it saves the redundant call and
     // 50-100ms.
     return true;
   }
 
   @Override
-  public Resource<Bitmap> decode(ParcelFileDescriptor resource, int outWidth, int outHeight,
-      Options options) throws IOException {
+  public Resource<Bitmap> decode(@NonNull ParcelFileDescriptor resource, int outWidth,
+      int outHeight, @NonNull Options options) throws IOException {
     long frameTimeMicros = options.get(TARGET_FRAME);
     if (frameTimeMicros < 0 && frameTimeMicros != DEFAULT_FRAME) {
       throw new IllegalArgumentException(
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bytes/BytesResource.java b/library/src/main/java/com/bumptech/glide/load/resource/bytes/BytesResource.java
index 6b0d7a2be2..6b8fde35e4 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/bytes/BytesResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/bytes/BytesResource.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.load.resource.bytes;
 
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.engine.Resource;
 import com.bumptech.glide.util.Preconditions;
 
@@ -13,11 +14,13 @@ public BytesResource(byte[] bytes) {
     this.bytes = Preconditions.checkNotNull(bytes);
   }
 
+  @NonNull
   @Override
   public Class<byte[]> getResourceClass() {
     return byte[].class;
   }
 
+  @NonNull
   @Override
   public byte[] get() {
     return bytes;
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/drawable/DrawableResource.java b/library/src/main/java/com/bumptech/glide/load/resource/drawable/DrawableResource.java
index 9a02e33653..17b74f2ccc 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/drawable/DrawableResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/drawable/DrawableResource.java
@@ -3,6 +3,7 @@
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.Drawable.ConstantState;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import com.bumptech.glide.load.engine.Initializable;
 import com.bumptech.glide.load.engine.Resource;
@@ -27,6 +28,7 @@ public DrawableResource(T drawable) {
     this.drawable = Preconditions.checkNotNull(drawable);
   }
 
+  @NonNull
   @SuppressWarnings("unchecked")
   @Override
   public final T get() {
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/drawable/NonOwnedDrawableResource.java b/library/src/main/java/com/bumptech/glide/load/resource/drawable/NonOwnedDrawableResource.java
index 616976a6c6..09b327382d 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/drawable/NonOwnedDrawableResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/drawable/NonOwnedDrawableResource.java
@@ -1,6 +1,7 @@
 package com.bumptech.glide.load.resource.drawable;
 
 import android.graphics.drawable.Drawable;
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.engine.Resource;
 
 /**
@@ -18,6 +19,7 @@ private NonOwnedDrawableResource(Drawable drawable) {
     super(drawable);
   }
 
+  @NonNull
   @SuppressWarnings("unchecked")
   @Override
   public Class<Drawable> getResourceClass() {
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java
index d1f5c1538b..da440845a5 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java
@@ -10,7 +10,6 @@
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
 import com.bumptech.glide.load.engine.Resource;
-import java.io.IOException;
 import java.util.List;
 
 /**
@@ -37,14 +36,14 @@ public ResourceDrawableDecoder(Context context) {
   }
 
   @Override
-  public boolean handles(Uri source, Options options) throws IOException {
+  public boolean handles(@NonNull Uri source, @NonNull Options options) {
     return source.getScheme().equals(ContentResolver.SCHEME_ANDROID_RESOURCE);
   }
 
   @NonNull
   @Override
-  public Resource<Drawable> decode(Uri source, int width, int height, Options options)
-      throws IOException {
+  public Resource<Drawable> decode(@NonNull Uri source, int width, int height,
+      @NonNull Options options) {
     @DrawableRes int resId = loadResourceIdFromUri(source);
     String packageName = source.getAuthority();
     Context toUse = packageName.equals(context.getPackageName())
@@ -69,23 +68,23 @@ private int loadResourceIdFromUri(Uri source) {
     List<String> segments = source.getPathSegments();
     @DrawableRes Integer result = null;
     if (segments.size() == NAME_URI_PATH_SEGMENTS) {
-       String packageName = source.getAuthority();
-       String typeName = segments.get(TYPE_PATH_SEGMENT_INDEX);
-       String resourceName = segments.get(NAME_PATH_SEGMENT_INDEX);
-       result = context.getResources().getIdentifier(resourceName, typeName, packageName);
+      String packageName = source.getAuthority();
+      String typeName = segments.get(TYPE_PATH_SEGMENT_INDEX);
+      String resourceName = segments.get(NAME_PATH_SEGMENT_INDEX);
+      result = context.getResources().getIdentifier(resourceName, typeName, packageName);
     } else if (segments.size() == ID_PATH_SEGMENTS) {
-       try {
-         result = Integer.valueOf(segments.get(RESOURCE_ID_SEGMENT_INDEX));
-       } catch (NumberFormatException e) {
-         // Ignored.
-       }
-     }
+      try {
+        result = Integer.valueOf(segments.get(RESOURCE_ID_SEGMENT_INDEX));
+      } catch (NumberFormatException e) {
+        // Ignored.
+      }
+    }
 
-     if (result == null) {
-       throw new IllegalArgumentException("Unrecognized Uri format: " + source);
-     } else if (result == 0) {
-       throw new IllegalArgumentException("Failed to obtain resource id for: " + source);
-     }
-     return result;
+    if (result == null) {
+      throw new IllegalArgumentException("Unrecognized Uri format: " + source);
+    } else if (result == 0) {
+      throw new IllegalArgumentException("Failed to obtain resource id for: " + source);
+    }
+    return result;
   }
 }
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/drawable/UnitDrawableDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/drawable/UnitDrawableDecoder.java
index 9c51437807..7ac9450c77 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/drawable/UnitDrawableDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/drawable/UnitDrawableDecoder.java
@@ -1,25 +1,25 @@
 package com.bumptech.glide.load.resource.drawable;
 
 import android.graphics.drawable.Drawable;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
 import com.bumptech.glide.load.engine.Resource;
-import java.io.IOException;
 
 /**
  * Passes through a {@link Drawable} as a {@link Drawable} based {@link Resource}.
  */
 public class UnitDrawableDecoder implements ResourceDecoder<Drawable, Drawable> {
   @Override
-  public boolean handles(Drawable source, Options options) throws IOException {
+  public boolean handles(@NonNull Drawable source, @NonNull Options options) {
     return true;
   }
 
   @Nullable
   @Override
-  public Resource<Drawable> decode(Drawable source, int width, int height, Options options)
-      throws IOException {
+  public Resource<Drawable> decode(@NonNull Drawable source, int width, int height,
+      @NonNull Options options) {
     return NonOwnedDrawableResource.newInstance(source);
   }
 }
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/file/FileDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/file/FileDecoder.java
index e932f3cafd..a5b3e13dd0 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/file/FileDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/file/FileDecoder.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.load.resource.file;
 
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
 import com.bumptech.glide.load.engine.Resource;
@@ -12,12 +13,13 @@
 public class FileDecoder implements ResourceDecoder<File, File> {
 
   @Override
-  public boolean handles(File source, Options options) {
+  public boolean handles(@NonNull File source, @NonNull Options options) {
     return true;
   }
 
   @Override
-  public Resource<File> decode(File source, int width, int height, Options options) {
+  public Resource<File> decode(@NonNull File source, int width, int height,
+      @NonNull Options options) {
     return new FileResource(source);
   }
 }
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/ByteBufferGifDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/ByteBufferGifDecoder.java
index 1561be7dc5..6781b922ad 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/gif/ByteBufferGifDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/ByteBufferGifDecoder.java
@@ -2,6 +2,8 @@
 
 import android.content.Context;
 import android.graphics.Bitmap;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.support.annotation.VisibleForTesting;
 import android.util.Log;
 import com.bumptech.glide.Glide;
@@ -70,13 +72,14 @@ public ByteBufferGifDecoder(
   }
 
   @Override
-  public boolean handles(ByteBuffer source, Options options) throws IOException {
+  public boolean handles(@NonNull ByteBuffer source, @NonNull Options options) throws IOException {
     return !options.get(GifOptions.DISABLE_ANIMATION)
         && ImageHeaderParserUtils.getType(parsers, source) == ImageType.GIF;
   }
 
   @Override
-  public GifDrawableResource decode(ByteBuffer source, int width, int height, Options options) {
+  public GifDrawableResource decode(@NonNull ByteBuffer source, int width, int height,
+      @NonNull Options options) {
     final GifHeaderParser parser = parserPool.obtain(source);
     try {
       return decode(source, width, height, parser, options);
@@ -85,6 +88,7 @@ public GifDrawableResource decode(ByteBuffer source, int width, int height, Opti
     }
   }
 
+  @Nullable
   private GifDrawableResource decode(
       ByteBuffer byteBuffer, int width, int height, GifHeaderParser parser, Options options) {
     long startTime = LogTime.getLogTime();
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifBitmapProvider.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifBitmapProvider.java
index 818d8a2f31..d2b5503c67 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifBitmapProvider.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifBitmapProvider.java
@@ -37,15 +37,16 @@ public GifBitmapProvider(BitmapPool bitmapPool, @Nullable ArrayPool arrayPool) {
 
   @NonNull
   @Override
-  public Bitmap obtain(int width, int height, Bitmap.Config config) {
+  public Bitmap obtain(int width, int height, @NonNull Bitmap.Config config) {
     return bitmapPool.getDirty(width, height, config);
   }
 
   @Override
-  public void release(Bitmap bitmap) {
+  public void release(@NonNull Bitmap bitmap) {
     bitmapPool.put(bitmap);
   }
 
+  @NonNull
   @Override
   public byte[] obtainByteArray(int size) {
     if (arrayPool == null) {
@@ -56,13 +57,14 @@ public byte[] obtainByteArray(int size) {
 
   @SuppressWarnings("PMD.UseVarargs")
   @Override
-  public void release(byte[] bytes) {
+  public void release(@NonNull byte[] bytes) {
     if (arrayPool == null) {
       return;
     }
     arrayPool.put(bytes);
   }
 
+  @NonNull
   @Override
   public int[] obtainIntArray(int size) {
     if (arrayPool == null) {
@@ -73,7 +75,7 @@ public int[] obtainIntArray(int size) {
 
   @SuppressWarnings("PMD.UseVarargs")
   @Override
-  public void release(int[] array) {
+  public void release(@NonNull int[] array) {
     if (arrayPool == null) {
       return;
     }
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawableResource.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawableResource.java
index 9a36f46219..090f279b88 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawableResource.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawableResource.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.load.resource.gif;
 
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.engine.Initializable;
 import com.bumptech.glide.load.resource.drawable.DrawableResource;
 
@@ -14,6 +15,7 @@ public GifDrawableResource(GifDrawable drawable) {
     super(drawable);
   }
 
+  @NonNull
   @Override
   public Class<GifDrawable> getResourceClass() {
     return GifDrawable.class;
@@ -21,7 +23,7 @@ public Class<GifDrawable> getResourceClass() {
 
   @Override
   public int getSize() {
-   return drawable.getSize();
+    return drawable.getSize();
   }
 
   @Override
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameResourceDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameResourceDecoder.java
index 4e887ed119..0fa7e28d58 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameResourceDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameResourceDecoder.java
@@ -1,6 +1,7 @@
 package com.bumptech.glide.load.resource.gif;
 
 import android.graphics.Bitmap;
+import android.support.annotation.NonNull;
 import com.bumptech.glide.gifdecoder.GifDecoder;
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
@@ -20,12 +21,13 @@ public GifFrameResourceDecoder(BitmapPool bitmapPool) {
   }
 
   @Override
-  public boolean handles(GifDecoder source, Options options) {
+  public boolean handles(@NonNull GifDecoder source, @NonNull Options options) {
     return true;
   }
 
   @Override
-  public Resource<Bitmap> decode(GifDecoder source, int width, int height, Options options) {
+  public Resource<Bitmap> decode(@NonNull GifDecoder source, int width, int height,
+      @NonNull Options options) {
     Bitmap bitmap = source.getNextFrame();
     return BitmapResource.obtain(bitmap, bitmapPool);
   }
diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/StreamGifDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/StreamGifDecoder.java
index 6f1e35632a..2cc3b848bb 100644
--- a/library/src/main/java/com/bumptech/glide/load/resource/gif/StreamGifDecoder.java
+++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/StreamGifDecoder.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.load.resource.gif;
 
+import android.support.annotation.NonNull;
 import android.util.Log;
 import com.bumptech.glide.load.ImageHeaderParser;
 import com.bumptech.glide.load.ImageHeaderParser.ImageType;
@@ -34,14 +35,14 @@ public StreamGifDecoder(List<ImageHeaderParser> parsers, ResourceDecoder<ByteBuf
   }
 
   @Override
-  public boolean handles(InputStream source, Options options) throws IOException {
+  public boolean handles(@NonNull InputStream source, @NonNull Options options) throws IOException {
     return !options.get(GifOptions.DISABLE_ANIMATION)
         && ImageHeaderParserUtils.getType(parsers, source, byteArrayPool) == ImageType.GIF;
   }
 
   @Override
-  public Resource<GifDrawable> decode(InputStream source, int width, int height,
-      Options options) throws IOException {
+  public Resource<GifDrawable> decode(@NonNull InputStream source, int width, int height,
+      @NonNull Options options) throws IOException {
     byte[] data = inputStreamToBytes(source);
     if (data == null) {
       return null;
diff --git a/library/src/test/java/com/bumptech/glide/load/resource/drawable/DrawableResourceTest.java b/library/src/test/java/com/bumptech/glide/load/resource/drawable/DrawableResourceTest.java
index 0a67150da8..50af60a7ae 100644
--- a/library/src/test/java/com/bumptech/glide/load/resource/drawable/DrawableResourceTest.java
+++ b/library/src/test/java/com/bumptech/glide/load/resource/drawable/DrawableResourceTest.java
@@ -27,6 +27,7 @@ public class DrawableResourceTest {
   public void setUp() {
     drawable = mock(TestDrawable.class);
     resource = new DrawableResource<TestDrawable>(drawable) {
+      @NonNull
       @Override
       public Class<TestDrawable> getResourceClass() {
         return TestDrawable.class;
@@ -72,6 +73,7 @@ public void get_withNullState_returnsOriginalDrawable() {
   @Test(expected = NullPointerException.class)
   public void testThrowsIfDrawableIsNull() {
     new DrawableResource<TestDrawable>(null) {
+      @NonNull
       @Override
       public Class<TestDrawable> getResourceClass() {
         return TestDrawable.class;
diff --git a/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgDecoder.java b/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgDecoder.java
index 4be16ad5b3..ad22122278 100644
--- a/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgDecoder.java
+++ b/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgDecoder.java
@@ -1,5 +1,6 @@
 package com.bumptech.glide.samples.svg;
 
+import android.support.annotation.NonNull;
 import com.bumptech.glide.load.Options;
 import com.bumptech.glide.load.ResourceDecoder;
 import com.bumptech.glide.load.engine.Resource;
@@ -15,12 +16,13 @@
 public class SvgDecoder implements ResourceDecoder<InputStream, SVG> {
 
   @Override
-  public boolean handles(InputStream source, Options options) throws IOException {
+  public boolean handles(@NonNull InputStream source, @NonNull Options options) {
     // TODO: Can we tell?
     return true;
   }
 
-  public Resource<SVG> decode(InputStream source, int width, int height, Options options)
+  public Resource<SVG> decode(@NonNull InputStream source, int width, int height,
+      @NonNull Options options)
       throws IOException {
     try {
       SVG svg = SVG.getFromInputStream(source);
diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
index 9589bde1c1..8aeaa634d3 100644
--- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
+++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifDecoder.java
@@ -3,6 +3,7 @@
 import android.graphics.Bitmap;
 import android.support.annotation.IntDef;
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import java.io.InputStream;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -44,40 +45,43 @@ interface BitmapProvider {
      *               android.graphics.Bitmap}.
      */
     @NonNull
-    Bitmap obtain(int width, int height, Bitmap.Config config);
+    Bitmap obtain(int width, int height, @NonNull Bitmap.Config config);
 
     /**
      * Releases the given Bitmap back to the pool.
      */
-    void release(Bitmap bitmap);
+    void release(@NonNull Bitmap bitmap);
 
     /**
      * Returns a byte array used for decoding and generating the frame bitmap.
      *
      * @param size the size of the byte array to obtain
      */
+    @NonNull
     byte[] obtainByteArray(int size);
 
     /**
      * Releases the given byte array back to the pool.
      */
-    void release(byte[] bytes);
+    void release(@NonNull byte[] bytes);
 
     /**
      * Returns an int array used for decoding/generating the frame bitmaps.
      */
+    @NonNull
     int[] obtainIntArray(int size);
 
     /**
      * Release the given array back to the pool.
      */
-    void release(int[] array);
+    void release(@NonNull int[] array);
   }
 
   int getWidth();
 
   int getHeight();
 
+  @NonNull
   ByteBuffer getData();
 
   /**
@@ -189,6 +193,7 @@ interface BitmapProvider {
    *
    * @return Bitmap representation of frame.
    */
+  @Nullable
   Bitmap getNextFrame();
 
   /**
@@ -198,15 +203,15 @@ interface BitmapProvider {
    * @return read status code (0 = no errors).
    */
   @GifDecodeStatus
-  int read(InputStream is, int contentLength);
+  int read(@Nullable InputStream is, int contentLength);
 
   void clear();
 
-  void setData(GifHeader header, byte[] data);
+  void setData(@NonNull GifHeader header, @NonNull byte[] data);
 
-  void setData(GifHeader header, ByteBuffer buffer);
+  void setData(@NonNull GifHeader header, @NonNull ByteBuffer buffer);
 
-  void setData(GifHeader header, ByteBuffer buffer, int sampleSize);
+  void setData(@NonNull GifHeader header, @NonNull ByteBuffer buffer, int sampleSize);
 
   /**
    * Reads GIF image from byte array.
@@ -215,7 +220,7 @@ interface BitmapProvider {
    * @return read status code (0 = no errors).
    */
   @GifDecodeStatus
-  int read(byte[] data);
+  int read(@Nullable byte[] data);
 
 
   /**
@@ -233,5 +238,5 @@ interface BitmapProvider {
    * {@link android.graphics.Bitmap.Config#ARGB_8888} will be used anyway to support the
    * transparency.
    */
-  void setDefaultBitmapConfig(Bitmap.Config format);
+  void setDefaultBitmapConfig(@NonNull Bitmap.Config format);
 }
diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
index 9b21d38d49..47f6e25df0 100644
--- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
+++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/GifHeaderParser.java
@@ -4,6 +4,8 @@
 import static com.bumptech.glide.gifdecoder.GifFrame.DISPOSAL_NONE;
 import static com.bumptech.glide.gifdecoder.GifFrame.DISPOSAL_UNSPECIFIED;
 
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.util.Log;
 import java.nio.BufferUnderflowException;
 import java.nio.ByteBuffer;
@@ -122,7 +124,7 @@ public class GifHeaderParser {
   private GifHeader header;
   private int blockSize = 0;
 
-  public GifHeaderParser setData(ByteBuffer data) {
+  public GifHeaderParser setData(@NonNull ByteBuffer data) {
     reset();
     rawData = data.asReadOnlyBuffer();
     rawData.position(0);
@@ -130,7 +132,7 @@ public GifHeaderParser setData(ByteBuffer data) {
     return this;
   }
 
-  public GifHeaderParser setData(byte[] data) {
+  public GifHeaderParser setData(@Nullable byte[] data) {
     if (data != null) {
       setData(ByteBuffer.wrap(data));
     } else {
@@ -152,6 +154,7 @@ private void reset() {
     blockSize = 0;
   }
 
+  @NonNull
   public GifHeader parseHeader() {
     if (rawData == null) {
       throw new IllegalStateException("You must call setData() before parseHeader()");
@@ -408,6 +411,7 @@ private void readLSD() {
    * @param nColors int number of colors to read.
    * @return int array containing 256 colors (packed ARGB with full alpha).
    */
+  @Nullable
   private int[] readColorTable(int nColors) {
     int nBytes = 3 * nColors;
     int[] tab = null;
diff --git a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java
index 7ba271baa5..4ce8a73c37 100644
--- a/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java
+++ b/third_party/gif_decoder/src/main/java/com/bumptech/glide/gifdecoder/StandardGifDecoder.java
@@ -122,19 +122,19 @@ public class StandardGifDecoder implements GifDecoder {
   // Public API.
   @SuppressWarnings("unused")
   public StandardGifDecoder(
-      GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData) {
+      @NonNull GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData) {
     this(provider, gifHeader, rawData, 1 /*sampleSize*/);
   }
 
   public StandardGifDecoder(
-      GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData,
+      @NonNull GifDecoder.BitmapProvider provider, GifHeader gifHeader, ByteBuffer rawData,
       int sampleSize) {
     this(provider);
     setData(gifHeader, rawData, sampleSize);
   }
 
   public StandardGifDecoder(
-      GifDecoder.BitmapProvider provider) {
+      @NonNull GifDecoder.BitmapProvider provider) {
     this.bitmapProvider = provider;
     header = new GifHeader();
   }
@@ -149,6 +149,7 @@ public int getHeight() {
     return header.height;
   }
 
+  @NonNull
   @Override
   public ByteBuffer getData() {
     return rawData;
@@ -227,6 +228,7 @@ public int getByteSize() {
     return rawData.limit() + mainPixels.length + (mainScratch.length * BYTES_PER_INTEGER);
   }
 
+  @Nullable
   @Override
   public synchronized Bitmap getNextFrame() {
     if (header.frameCount <= 0 || framePointer < 0) {
@@ -283,7 +285,7 @@ public synchronized Bitmap getNextFrame() {
   }
 
   @Override
-  public int read(InputStream is, int contentLength) {
+  public int read(@Nullable InputStream is, int contentLength) {
     if (is != null) {
       try {
         int capacity = (contentLength > 0) ? (contentLength + 4 * 1024) : 16 * 1024;
@@ -335,17 +337,18 @@ public void clear() {
   }
 
   @Override
-  public synchronized void setData(GifHeader header, byte[] data) {
+  public synchronized void setData(@NonNull GifHeader header, @NonNull byte[] data) {
     setData(header, ByteBuffer.wrap(data));
   }
 
   @Override
-  public synchronized void setData(GifHeader header, ByteBuffer buffer) {
+  public synchronized void setData(@NonNull GifHeader header, @NonNull ByteBuffer buffer) {
     setData(header, buffer, 1);
   }
 
   @Override
-  public synchronized void setData(GifHeader header, ByteBuffer buffer, int sampleSize) {
+  public synchronized void setData(@NonNull GifHeader header, @NonNull ByteBuffer buffer,
+      int sampleSize) {
     if (sampleSize <= 0) {
       throw new IllegalArgumentException("Sample size must be >=0, not: " + sampleSize);
     }
@@ -377,6 +380,7 @@ public synchronized void setData(GifHeader header, ByteBuffer buffer, int sample
     mainScratch = bitmapProvider.obtainIntArray(downsampledWidth * downsampledHeight);
   }
 
+  @NonNull
   private GifHeaderParser getHeaderParser() {
     if (parser == null) {
       parser = new GifHeaderParser();
@@ -386,7 +390,7 @@ private GifHeaderParser getHeaderParser() {
 
   @Override
   @GifDecodeStatus
-  public synchronized int read(byte[] data) {
+  public synchronized int read(@Nullable byte[] data) {
     this.header = getHeaderParser().setData(data).parseHeader();
     if (data != null) {
       setData(header, data);
@@ -396,7 +400,7 @@ public synchronized int read(byte[] data) {
   }
 
   @Override
-  public void setDefaultBitmapConfig(Bitmap.Config config) {
+  public void setDefaultBitmapConfig(@NonNull Bitmap.Config config) {
     if (config != Bitmap.Config.ARGB_8888 && config != Bitmap.Config.RGB_565) {
       throw new IllegalArgumentException("Unsupported format: " + config
           + ", must be one of " + Bitmap.Config.ARGB_8888 + " or " + Bitmap.Config.RGB_565);
@@ -730,7 +734,7 @@ private void decodeBitmapData(GifFrame frame) {
     // Decode GIF pixel stream.
     i = datum = bits = count = first = top = pi = bi = 0;
     while (i < npix) {
-        // Read a new data block.
+      // Read a new data block.
       if (count == 0) {
         count = readBlock();
         if (count <= 0) {
diff --git a/third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java b/third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java
index 13a5813035..cc25027e0d 100644
--- a/third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java
+++ b/third_party/gif_decoder/src/test/java/com/bumptech/glide/gifdecoder/GifDecoderTest.java
@@ -197,27 +197,29 @@ public Bitmap obtain(int width, int height, Bitmap.Config config) {
     }
 
     @Override
-    public void release(Bitmap bitmap) {
+    public void release(@NonNull Bitmap bitmap) {
       // Do nothing.
     }
 
+    @NonNull
     @Override
     public byte[] obtainByteArray(int size) {
       return new byte[size];
     }
 
     @Override
-    public void release(byte[] bytes) {
+    public void release(@NonNull byte[] bytes) {
       // Do nothing.
     }
 
+    @NonNull
     @Override
     public int[] obtainIntArray(int size) {
       return new int[size];
     }
 
     @Override
-    public void release(int[] array) {
+    public void release(@NonNull int[] array) {
       // Do Nothing
     }
 
diff --git a/third_party/gif_encoder/src/main/java/com/bumptech/glide/gifencoder/AnimatedGifEncoder.java b/third_party/gif_encoder/src/main/java/com/bumptech/glide/gifencoder/AnimatedGifEncoder.java
index 7bb25acabe..f05bd08b82 100644
--- a/third_party/gif_encoder/src/main/java/com/bumptech/glide/gifencoder/AnimatedGifEncoder.java
+++ b/third_party/gif_encoder/src/main/java/com/bumptech/glide/gifencoder/AnimatedGifEncoder.java
@@ -4,6 +4,8 @@
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.util.Log;
 import java.io.BufferedOutputStream;
 import java.io.FileOutputStream;
@@ -152,7 +154,7 @@ public void setTransparent(int color) {
      *          BufferedImage containing frame to write.
      * @return true if successful.
      */
-    public boolean addFrame(Bitmap im) {
+    public boolean addFrame(@Nullable Bitmap im) {
         return addFrame(im, 0, 0);
     }
 
@@ -175,7 +177,7 @@ public boolean addFrame(Bitmap im) {
      *          the Logical Screen.
      * @return true if successful.
      */
-    public boolean addFrame(Bitmap im, int x, int y) {
+    public boolean addFrame(@Nullable Bitmap im, int x, int y) {
         if ((im == null) || !started) {
             return false;
         }
@@ -318,7 +320,7 @@ private void setFrameSize(int w, int h) {
      *          OutputStream on which GIF images are written.
      * @return false if initial write failed.
      */
-    public boolean start(OutputStream os) {
+    public boolean start(@Nullable OutputStream os) {
         if (os == null)
             return false;
         boolean ok = true;
@@ -339,8 +341,8 @@ public boolean start(OutputStream os) {
      *          String containing output file name.
      * @return false if open or initial write failed.
      */
-    public boolean start(String file) {
-        boolean ok = true;
+    public boolean start(@NonNull String file) {
+        boolean ok;
         try {
             out = new BufferedOutputStream(new FileOutputStream(file));
             ok = start(out);