diff --git a/instrumentation/src/androidTest/java/com/bumptech/glide/ErrorHandlingTest.java b/instrumentation/src/androidTest/java/com/bumptech/glide/ErrorHandlingTest.java index 402984f1c1..2e4898227a 100644 --- a/instrumentation/src/androidTest/java/com/bumptech/glide/ErrorHandlingTest.java +++ b/instrumentation/src/androidTest/java/com/bumptech/glide/ErrorHandlingTest.java @@ -49,7 +49,7 @@ public class ErrorHandlingTest { private Context context; @Before - public void setUp() throws InterruptedException { + public void setUp() { MockitoAnnotations.initMocks(this); context = InstrumentationRegistry.getTargetContext(); } @@ -82,8 +82,7 @@ public void load_whenEncoderFails_callsUncaughtThrowableStrategy() { } @Test - public void load_whenLoadSucceeds_butEncoderFails_doesNotCallOnLoadFailed() - throws InterruptedException { + public void load_whenLoadSucceeds_butEncoderFails_doesNotCallOnLoadFailed() { WaitForErrorStrategy strategy = new WaitForErrorStrategy(); Glide.init(context, new GlideBuilder() @@ -110,8 +109,7 @@ public void load_whenLoadSucceeds_butEncoderFails_doesNotCallOnLoadFailed() } @Test - public void clearRequest_withError_afterPrimaryFails_clearsErrorRequest() - throws InterruptedException { + public void clearRequest_withError_afterPrimaryFails_clearsErrorRequest() { WaitModel errorModel = WaitModelLoader.Factory.waitOn(ResourceIds.raw.canonical); FutureTarget target = @@ -151,6 +149,7 @@ private static final class FailEncoder implements ResourceEncoder { static final RuntimeException TO_THROW = new RuntimeException(); + @NonNull @Override public EncodeStrategy getEncodeStrategy(@NonNull Options options) { return EncodeStrategy.TRANSFORMED; diff --git a/integration/gifencoder/src/main/java/com/bumptech/glide/integration/gifencoder/ReEncodingGifResourceEncoder.java b/integration/gifencoder/src/main/java/com/bumptech/glide/integration/gifencoder/ReEncodingGifResourceEncoder.java index e8a390fddb..0d67e6fd72 100644 --- a/integration/gifencoder/src/main/java/com/bumptech/glide/integration/gifencoder/ReEncodingGifResourceEncoder.java +++ b/integration/gifencoder/src/main/java/com/bumptech/glide/integration/gifencoder/ReEncodingGifResourceEncoder.java @@ -53,7 +53,8 @@ public class ReEncodingGifResourceEncoder implements ResourceEncoder ENCODE_TRANSFORMATION = Option.disk(KEY_ENCODE_TRANSFORMATION, false, new Option.CacheKeyUpdater() { @Override - public void update(byte[] keyBytes, Boolean value, MessageDigest messageDigest) { + public void update(@NonNull byte[] keyBytes, @NonNull Boolean value, + @NonNull MessageDigest messageDigest) { if (value) { messageDigest.update(keyBytes); } @@ -81,6 +82,7 @@ public ReEncodingGifResourceEncoder(@NonNull Context context, @NonNull BitmapPoo this.factory = factory; } + @NonNull @Override public EncodeStrategy getEncodeStrategy(@NonNull Options options) { Boolean encodeTransformation = options.get(ENCODE_TRANSFORMATION); @@ -213,7 +215,8 @@ AnimatedGifEncoder buildEncoder() { return new AnimatedGifEncoder(); } - Resource buildFrameResource(Bitmap bitmap, BitmapPool bitmapPool) { + @NonNull + Resource buildFrameResource(@NonNull Bitmap bitmap, @NonNull BitmapPool bitmapPool) { return new BitmapResource(bitmap, bitmapPool); } } diff --git a/library/src/main/java/com/bumptech/glide/load/ImageHeaderParser.java b/library/src/main/java/com/bumptech/glide/load/ImageHeaderParser.java index 52463e74a7..b188c4df34 100644 --- a/library/src/main/java/com/bumptech/glide/load/ImageHeaderParser.java +++ b/library/src/main/java/com/bumptech/glide/load/ImageHeaderParser.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load; +import android.support.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; import java.io.IOException; import java.io.InputStream; @@ -10,9 +11,9 @@ */ public interface ImageHeaderParser { /** - * A constant indicating we were unable to parse the orientation from the image either because - * no exif segment containing orientation data existed, or because of an I/O error attempting to - * read the exif segment. + * A constant indicating we were unable to parse the orientation from the image either because no + * exif segment containing orientation data existed, or because of an I/O error attempting to read + * the exif segment. */ int UNKNOWN_ORIENTATION = -1; @@ -32,10 +33,9 @@ enum ImageType { WEBP_A(true), /** WebP type without alpha. */ WEBP(false), - /** - * Unrecognized type. - */ + /** Unrecognized type. */ UNKNOWN(false); + private final boolean hasAlpha; ImageType(boolean hasAlpha) { @@ -47,8 +47,11 @@ public boolean hasAlpha() { } } - ImageType getType(InputStream is) throws IOException; - ImageType getType(ByteBuffer byteBuffer) throws IOException; + @NonNull + ImageType getType(@NonNull InputStream is) throws IOException; + + @NonNull + ImageType getType(@NonNull ByteBuffer byteBuffer) throws IOException; /** * Parse the orientation from the image header. If it doesn't handle this image type (or this is @@ -57,6 +60,8 @@ public boolean hasAlpha() { * @return The exif orientation if present or -1 if the header couldn't be parsed or doesn't * contain an orientation */ - int getOrientation(InputStream is, ArrayPool byteArrayPool) throws IOException; - int getOrientation(ByteBuffer byteBuffer, ArrayPool byteArrayPool) throws IOException; + int getOrientation(@NonNull InputStream is, @NonNull ArrayPool byteArrayPool) throws IOException; + + int getOrientation(@NonNull ByteBuffer byteBuffer, @NonNull ArrayPool byteArrayPool) + throws IOException; } diff --git a/library/src/main/java/com/bumptech/glide/load/ImageHeaderParserUtils.java b/library/src/main/java/com/bumptech/glide/load/ImageHeaderParserUtils.java index d790108ec0..97930be119 100644 --- a/library/src/main/java/com/bumptech/glide/load/ImageHeaderParserUtils.java +++ b/library/src/main/java/com/bumptech/glide/load/ImageHeaderParserUtils.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.ImageHeaderParser.ImageType; import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; @@ -20,8 +21,9 @@ public final class ImageHeaderParserUtils { private ImageHeaderParserUtils() { } /** Returns the ImageType for the given InputStream. */ - public static ImageType getType(List parsers, @Nullable InputStream is, - ArrayPool byteArrayPool) throws IOException { + @NonNull + public static ImageType getType(@NonNull List parsers, + @Nullable InputStream is, @NonNull ArrayPool byteArrayPool) throws IOException { if (is == null) { return ImageType.UNKNOWN; } @@ -48,7 +50,9 @@ public static ImageType getType(List parsers, @Nullable Input } /** Returns the ImageType for the given ByteBuffer. */ - public static ImageType getType(List parsers, @Nullable ByteBuffer buffer) + @NonNull + public static ImageType getType(@NonNull List parsers, + @Nullable ByteBuffer buffer) throws IOException { if (buffer == null) { return ImageType.UNKNOWN; @@ -66,9 +70,11 @@ public static ImageType getType(List parsers, @Nullable ByteB return ImageType.UNKNOWN; } - /** Returns the orientation for the given InputStream. */ - public static int getOrientation(List parsers, @Nullable InputStream is, - ArrayPool byteArrayPool) throws IOException { + /** + * Returns the orientation for the given InputStream. + */ + public static int getOrientation(@NonNull List parsers, + @Nullable InputStream is, @NonNull ArrayPool byteArrayPool) throws IOException { if (is == null) { return ImageHeaderParser.UNKNOWN_ORIENTATION; } diff --git a/library/src/main/java/com/bumptech/glide/load/Key.java b/library/src/main/java/com/bumptech/glide/load/Key.java index 2e7fd07f84..f78a7b168c 100644 --- a/library/src/main/java/com/bumptech/glide/load/Key.java +++ b/library/src/main/java/com/bumptech/glide/load/Key.java @@ -24,9 +24,17 @@ public interface Key { */ void updateDiskCacheKey(@NonNull MessageDigest messageDigest); + /** + * For caching to work correctly, implementations must implement this method and + * {@link #hashCode()}. + */ @Override boolean equals(Object o); + /** + * For caching to work correctly, implementations must implement this method and + * {@link #equals(Object)}. + */ @Override int hashCode(); } diff --git a/library/src/main/java/com/bumptech/glide/load/MultiTransformation.java b/library/src/main/java/com/bumptech/glide/load/MultiTransformation.java index aaac6cd684..6b1d038f2f 100644 --- a/library/src/main/java/com/bumptech/glide/load/MultiTransformation.java +++ b/library/src/main/java/com/bumptech/glide/load/MultiTransformation.java @@ -17,7 +17,7 @@ public class MultiTransformation implements Transformation { @SafeVarargs @SuppressWarnings("varargs") - public MultiTransformation(Transformation... transformations) { + public MultiTransformation(@NonNull Transformation... transformations) { if (transformations.length == 0) { throw new IllegalArgumentException( "MultiTransformation must contain at least one Transformation"); @@ -25,7 +25,7 @@ public MultiTransformation(Transformation... transformations) { this.transformations = Arrays.asList(transformations); } - public MultiTransformation(Collection> transformationList) { + public MultiTransformation(@NonNull Collection> transformationList) { if (transformationList.isEmpty()) { throw new IllegalArgumentException( "MultiTransformation must contain at least one Transformation"); diff --git a/library/src/main/java/com/bumptech/glide/load/Option.java b/library/src/main/java/com/bumptech/glide/load/Option.java index f6b2e1dbc5..561264871f 100644 --- a/library/src/main/java/com/bumptech/glide/load/Option.java +++ b/library/src/main/java/com/bumptech/glide/load/Option.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.bumptech.glide.util.Preconditions; import java.security.MessageDigest; @@ -26,7 +27,8 @@ public final class Option { private static final CacheKeyUpdater EMPTY_UPDATER = new CacheKeyUpdater() { @Override - public void update(byte[] keyBytes, Object value, MessageDigest messageDigest) { + public void update(@NonNull byte[] keyBytes, @NonNull Object value, + @NonNull MessageDigest messageDigest) { // Do nothing. } }; @@ -43,8 +45,9 @@ public void update(byte[] keyBytes, Object value, MessageDigest messageDigest) { * @param key A unique package prefixed {@link String} that identifies this option (must be * stable across builds, so {@link Class#getName()} should not be used). */ - public static Option memory(String key) { - return new Option<>(key, null /*defaultValue*/, Option.emptyUpdater()); + @NonNull + public static Option memory(@NonNull String key) { + return new Option<>(key, null, Option.emptyUpdater()); } /** @@ -54,7 +57,8 @@ public static Option memory(String key) { * @param key A unique package prefixed {@link String} that identifies this option (must be * stable across builds, so {@link Class#getName()} should not be used). */ - public static Option memory(String key, T defaultValue) { + @NonNull + public static Option memory(@NonNull String key, @NonNull T defaultValue) { return new Option<>(key, defaultValue, Option.emptyUpdater()); } @@ -65,8 +69,10 @@ public static Option memory(String key, T defaultValue) { * @param key A unique package prefixed {@link String} that identifies this option (must be * stable across builds, so {@link Class#getName()} should not be used). */ - public static Option disk(String key, CacheKeyUpdater cacheKeyUpdater) { - return new Option<>(key, null /*defaultValue*/, cacheKeyUpdater); + @NonNull + public static Option disk(@NonNull String key, + @NonNull CacheKeyUpdater cacheKeyUpdater) { + return new Option<>(key, null, cacheKeyUpdater); } /** @@ -77,11 +83,14 @@ public static Option disk(String key, CacheKeyUpdater cacheKeyUpdater) * @param key A unique package prefixed {@link String} that identifies this option (must be * stable across builds, so {@link Class#getName()} should not be used). */ - public static Option disk(String key, T defaultValue, CacheKeyUpdater cacheKeyUpdater) { + @NonNull + public static Option disk(@NonNull String key, @Nullable T defaultValue, + @NonNull CacheKeyUpdater cacheKeyUpdater) { return new Option<>(key, defaultValue, cacheKeyUpdater); } - private Option(String key, T defaultValue, CacheKeyUpdater cacheKeyUpdater) { + private Option(@NonNull String key, @Nullable T defaultValue, + @NonNull CacheKeyUpdater cacheKeyUpdater) { this.key = Preconditions.checkNotEmpty(key); this.defaultValue = defaultValue; this.cacheKeyUpdater = Preconditions.checkNotNull(cacheKeyUpdater); @@ -102,10 +111,11 @@ public T getDefaultValue() { * value using the {@link com.bumptech.glide.load.Option.CacheKeyUpdater} optionally provided in * the constructor. */ - public void update(T value, MessageDigest messageDigest) { + public void update(@NonNull T value, @NonNull MessageDigest messageDigest) { cacheKeyUpdater.update(getKeyBytes(), value, messageDigest); } + @NonNull private byte[] getKeyBytes() { if (keyBytes == null) { keyBytes = key.getBytes(Key.CHARSET); @@ -127,6 +137,7 @@ public int hashCode() { return key.hashCode(); } + @NonNull @SuppressWarnings("unchecked") private static CacheKeyUpdater emptyUpdater() { return (CacheKeyUpdater) EMPTY_UPDATER; @@ -162,6 +173,6 @@ public interface CacheKeyUpdater { * to a byte array using some stable mechanism and then call * {@link MessageDigest#update(byte[])} to update the given digest. */ - void update(byte[] keyBytes, T value, MessageDigest messageDigest); + void update(@NonNull byte[] keyBytes, @NonNull T value, @NonNull MessageDigest messageDigest); } } diff --git a/library/src/main/java/com/bumptech/glide/load/Options.java b/library/src/main/java/com/bumptech/glide/load/Options.java index 5ca52c84b8..bf2685323e 100644 --- a/library/src/main/java/com/bumptech/glide/load/Options.java +++ b/library/src/main/java/com/bumptech/glide/load/Options.java @@ -1,6 +1,7 @@ package com.bumptech.glide.load; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.util.ArrayMap; import android.support.v4.util.SimpleArrayMap; import java.security.MessageDigest; @@ -11,17 +12,19 @@ public final class Options implements Key { private final ArrayMap, Object> values = new ArrayMap<>(); - public void putAll(Options other) { + public void putAll(@NonNull Options other) { values.putAll((SimpleArrayMap, Object>) other.values); } - public Options set(Option option, T value) { + @NonNull + public Options set(@NonNull Option option, @NonNull T value) { values.put(option, value); return this; } + @Nullable @SuppressWarnings("unchecked") - public T get(Option option) { + public T get(@NonNull Option option) { return values.containsKey(option) ? (T) values.get(option) : option.getDefaultValue(); } @@ -56,7 +59,8 @@ public String toString() { } @SuppressWarnings("unchecked") - private static void updateDiskCacheKey(Option option, Object value, MessageDigest md) { + private static void updateDiskCacheKey(@NonNull Option option, @NonNull Object value, + @NonNull MessageDigest md) { option.update((T) value, md); } } diff --git a/library/src/main/java/com/bumptech/glide/load/ResourceEncoder.java b/library/src/main/java/com/bumptech/glide/load/ResourceEncoder.java index c0f5f13bac..d179858451 100644 --- a/library/src/main/java/com/bumptech/glide/load/ResourceEncoder.java +++ b/library/src/main/java/com/bumptech/glide/load/ResourceEncoder.java @@ -11,5 +11,6 @@ */ public interface ResourceEncoder extends Encoder> { // specializing the generic arguments + @NonNull EncodeStrategy getEncodeStrategy(@NonNull Options options); } diff --git a/library/src/main/java/com/bumptech/glide/load/Transformation.java b/library/src/main/java/com/bumptech/glide/load/Transformation.java index 996a20cd1a..2e9ab29d96 100644 --- a/library/src/main/java/com/bumptech/glide/load/Transformation.java +++ b/library/src/main/java/com/bumptech/glide/load/Transformation.java @@ -65,18 +65,4 @@ public interface Transformation extends Key { @NonNull Resource transform(@NonNull Context context, @NonNull Resource resource, int outWidth, int outHeight); - - /** - * For caching to work correctly, implementations must implement this method and - * {@link #hashCode()}. - */ - @Override - boolean equals(Object o); - - /** - * For caching to work correctly, implementations must implement this method and - * {@link #equals(Object)}. - */ - @Override - int hashCode(); } diff --git a/library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java b/library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java index 35a35ce80f..3fe0bb3d5e 100644 --- a/library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java +++ b/library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java @@ -140,8 +140,8 @@ boolean willDecodeFromCache() { /** * Called when this object is no longer in use externally. * - * @param isRemovedFromQueue {@code true} if we've been removed from the queue and {@link #run} - * is neither in progress nor will ever be called again. + * @param isRemovedFromQueue {@code true} if we've been removed from the queue and {@link #run} is + * neither in progress nor will ever be called again. */ void release(boolean isRemovedFromQueue) { if (releaseManager.release(isRemovedFromQueue)) { @@ -259,7 +259,7 @@ public void run() { } private void runWrapped() { - switch (runReason) { + switch (runReason) { case INITIALIZE: stage = getNextStage(Stage.INITIALIZE); currentGenerator = getNextGenerator(); @@ -399,8 +399,8 @@ private void decodeFromRetrievedData() { if (Log.isLoggable(TAG, Log.VERBOSE)) { logWithTimeAndKey("Retrieved data", startFetchTime, "data: " + currentData - + ", cache key: " + currentSourceKey - + ", fetcher: " + currentFetcher); + + ", cache key: " + currentSourceKey + + ", fetcher: " + currentFetcher); } Resource resource = null; try { @@ -469,6 +469,7 @@ private Resource decodeFromFetcher(Data data, DataSource dataSource) return runLoadPath(data, dataSource, path); } + @NonNull private Options getOptionsWithHardwareConfig(DataSource dataSource) { Options options = this.options; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { @@ -517,7 +518,10 @@ public StateVerifier getVerifier() { return stateVerifier; } - @Synthetic Resource onResourceDecoded(DataSource dataSource, Resource decoded) { + @Synthetic + @NonNull + Resource onResourceDecoded(DataSource dataSource, + @NonNull Resource decoded) { @SuppressWarnings("unchecked") Class resourceSubClass = (Class) decoded.get().getClass(); Transformation appliedTransformation = null; @@ -585,8 +589,9 @@ private final class DecodeCallback implements DecodePath.DecodeCallback { this.dataSource = dataSource; } + @NonNull @Override - public Resource onResourceDecoded(Resource decoded) { + public Resource onResourceDecoded(@NonNull Resource decoded) { return DecodeJob.this.onResourceDecoded(dataSource, decoded); } } @@ -629,8 +634,8 @@ private boolean isComplete(boolean isRemovedFromQueue) { } /** - * Allows transformed resources to be encoded after the transcoded result is already delivered - * to requestors. + * Allows transformed resources to be encoded after the transcoded result is already delivered to + * requestors. */ private static class DeferredEncodeManager { private Key key; diff --git a/library/src/main/java/com/bumptech/glide/load/engine/DecodePath.java b/library/src/main/java/com/bumptech/glide/load/engine/DecodePath.java index b9e2704a79..919dc7584a 100644 --- a/library/src/main/java/com/bumptech/glide/load/engine/DecodePath.java +++ b/library/src/main/java/com/bumptech/glide/load/engine/DecodePath.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.engine; +import android.support.annotation.NonNull; import android.support.v4.util.Pools.Pool; import android.util.Log; import com.bumptech.glide.load.Options; @@ -40,14 +41,15 @@ public DecodePath(Class dataClass, Class resourceClass, } public Resource decode(DataRewinder rewinder, int width, int height, - Options options, DecodeCallback callback) throws GlideException { + @NonNull Options options, DecodeCallback callback) throws GlideException { Resource decoded = decodeResource(rewinder, width, height, options); Resource transformed = callback.onResourceDecoded(decoded); return transcoder.transcode(transformed, options); } + @NonNull private Resource decodeResource(DataRewinder rewinder, int width, - int height, Options options) throws GlideException { + int height, @NonNull Options options) throws GlideException { List exceptions = Preconditions.checkNotNull(listPool.acquire()); try { return decodeResourceWithList(rewinder, width, height, options, exceptions); @@ -56,8 +58,9 @@ private Resource decodeResource(DataRewinder rewinder, i } } + @NonNull private Resource decodeResourceWithList(DataRewinder rewinder, int width, - int height, Options options, List exceptions) throws GlideException { + int height, @NonNull Options options, List exceptions) throws GlideException { Resource result = null; //noinspection ForLoopReplaceableByForEach to improve perf for (int i = 0, size = decoders.size(); i < size; i++) { @@ -95,6 +98,7 @@ public String toString() { } interface DecodeCallback { - Resource onResourceDecoded(Resource resource); + @NonNull + Resource onResourceDecoded(@NonNull Resource resource); } } diff --git a/library/src/main/java/com/bumptech/glide/load/engine/LoadPath.java b/library/src/main/java/com/bumptech/glide/load/engine/LoadPath.java index fd50d328a1..dca8f89529 100644 --- a/library/src/main/java/com/bumptech/glide/load/engine/LoadPath.java +++ b/library/src/main/java/com/bumptech/glide/load/engine/LoadPath.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.engine; +import android.support.annotation.NonNull; import android.support.v4.util.Pools.Pool; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.data.DataRewinder; @@ -35,7 +36,7 @@ public LoadPath(Class dataClass, Class resourceClass, + resourceClass.getSimpleName() + "->" + transcodeClass.getSimpleName() + "}"; } - public Resource load(DataRewinder rewinder, Options options, int width, + public Resource load(DataRewinder rewinder, @NonNull Options options, int width, int height, DecodePath.DecodeCallback decodeCallback) throws GlideException { List throwables = Preconditions.checkNotNull(listPool.acquire()); try { @@ -45,7 +46,8 @@ public Resource load(DataRewinder rewinder, Options options, in } } - private Resource loadWithExceptionList(DataRewinder rewinder, Options options, + private Resource loadWithExceptionList(DataRewinder rewinder, + @NonNull Options options, int width, int height, DecodePath.DecodeCallback decodeCallback, List exceptions) throws GlideException { Resource result = null; 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 c1c43ec6ea..594b264414 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 @@ -29,6 +29,7 @@ public LockedResource create() { private boolean isRecycled; @SuppressWarnings("unchecked") + @NonNull static LockedResource obtain(Resource resource) { LockedResource result = Preconditions.checkNotNull((LockedResource) POOL.acquire()); result.init(resource); 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 1ee1ac609b..9b6c8e465c 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 @@ -15,7 +15,7 @@ public class SimpleResource implements Resource { protected final T data; - public SimpleResource(T data) { + public SimpleResource(@NonNull T data) { this.data = Preconditions.checkNotNull(data); } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/UnitTransformation.java b/library/src/main/java/com/bumptech/glide/load/resource/UnitTransformation.java index d5da9985ee..9602c25642 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/UnitTransformation.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/UnitTransformation.java @@ -20,6 +20,7 @@ public final class UnitTransformation implements Transformation { * @param The type of the resource to be transformed. */ @SuppressWarnings("unchecked") + @NonNull public static UnitTransformation get() { return (UnitTransformation) TRANSFORMATION; } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableEncoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableEncoder.java index 656bdf66c5..a955d9d059 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableEncoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableEncoder.java @@ -29,6 +29,7 @@ public boolean encode(@NonNull Resource data, @NonNull File file return encoder.encode(new BitmapResource(data.get().getBitmap(), bitmapPool), file, options); } + @NonNull @Override public EncodeStrategy getEncodeStrategy(@NonNull Options options) { return encoder.getEncodeStrategy(options); diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableTransformation.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableTransformation.java index b0dc28cb2c..a783e616c4 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableTransformation.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableTransformation.java @@ -48,11 +48,11 @@ public BitmapDrawableTransformation( this(wrapped); } + @NonNull @Override public Resource transform( - Context context, Resource drawableResourceToTransform, int outWidth, - int outHeight) { - + @NonNull Context context, @NonNull Resource drawableResourceToTransform, + int outWidth, int outHeight) { Resource toTransform = convertToDrawableResource(drawableResourceToTransform); Resource transformed = wrapped.transform(context, toTransform, outWidth, outHeight); return convertToBitmapDrawableResource(transformed); diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapEncoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapEncoder.java index 8de58d9a30..5c949e6e3e 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapEncoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapEncoder.java @@ -125,6 +125,7 @@ private Bitmap.CompressFormat getFormat(Bitmap bitmap, Options options) { } } + @NonNull @Override public EncodeStrategy getEncodeStrategy(@NonNull Options options) { return EncodeStrategy.TRANSFORMED; diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/DefaultImageHeaderParser.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/DefaultImageHeaderParser.java index a2252613bc..a6e7c10cbb 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/DefaultImageHeaderParser.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/DefaultImageHeaderParser.java @@ -6,6 +6,7 @@ import static com.bumptech.glide.load.ImageHeaderParser.ImageType.PNG_A; import static com.bumptech.glide.load.ImageHeaderParser.ImageType.UNKNOWN; +import android.support.annotation.NonNull; import android.util.Log; import com.bumptech.glide.load.ImageHeaderParser; import com.bumptech.glide.load.engine.bitmap_recycle.ArrayPool; @@ -56,28 +57,33 @@ public final class DefaultImageHeaderParser implements ImageHeaderParser { private static final int WEBP_EXTENDED_ALPHA_FLAG = 1 << 4; private static final int WEBP_LOSSLESS_ALPHA_FLAG = 1 << 3; + @NonNull @Override - public ImageType getType(InputStream is) throws IOException { + public ImageType getType(@NonNull InputStream is) throws IOException { return getType(new StreamReader(Preconditions.checkNotNull(is))); } + @NonNull @Override - public ImageType getType(ByteBuffer byteBuffer) throws IOException { + public ImageType getType(@NonNull ByteBuffer byteBuffer) throws IOException { return getType(new ByteBufferReader(Preconditions.checkNotNull(byteBuffer))); } @Override - public int getOrientation(InputStream is, ArrayPool byteArrayPool) throws IOException { + public int getOrientation(@NonNull InputStream is, @NonNull ArrayPool byteArrayPool) + throws IOException { return getOrientation(new StreamReader(Preconditions.checkNotNull(is)), Preconditions.checkNotNull(byteArrayPool)); } @Override - public int getOrientation(ByteBuffer byteBuffer, ArrayPool byteArrayPool) throws IOException { + public int getOrientation(@NonNull ByteBuffer byteBuffer, @NonNull ArrayPool byteArrayPool) + throws IOException { return getOrientation(new ByteBufferReader(Preconditions.checkNotNull(byteBuffer)), Preconditions.checkNotNull(byteArrayPool)); } + @NonNull private ImageType getType(Reader reader) throws IOException { final int firstTwoBytes = reader.getUInt16(); @@ -232,13 +238,13 @@ private int moveToExifSegmentAndGetLength(Reader reader) throws IOException { if (segmentType != EXIF_SEGMENT_TYPE) { long skipped = reader.skip(segmentLength); if (skipped != segmentLength) { - if (Log.isLoggable(TAG, Log.DEBUG)) { - Log.d(TAG, "Unable to skip enough data" - + ", type: " + segmentType - + ", wanted to skip: " + segmentLength - + ", but actually skipped: " + skipped); - } - return -1; + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "Unable to skip enough data" + + ", type: " + segmentType + + ", wanted to skip: " + segmentLength + + ", but actually skipped: " + skipped); + } + return -1; } } else { return segmentLength; @@ -389,24 +395,24 @@ private static final class ByteBufferReader implements Reader { } @Override - public int getUInt16() throws IOException { + public int getUInt16() { return (getByte() << 8 & 0xFF00) | (getByte() & 0xFF); } @Override - public short getUInt8() throws IOException { + public short getUInt8() { return (short) (getByte() & 0xFF); } @Override - public long skip(long total) throws IOException { + public long skip(long total) { int toSkip = (int) Math.min(byteBuffer.remaining(), total); byteBuffer.position(byteBuffer.position() + toSkip); return toSkip; } @Override - public int read(byte[] buffer, int byteCount) throws IOException { + public int read(byte[] buffer, int byteCount) { int toRead = Math.min(byteCount, byteBuffer.remaining()); if (toRead == 0) { return -1; @@ -416,7 +422,7 @@ public int read(byte[] buffer, int byteCount) throws IOException { } @Override - public int getByte() throws IOException { + public int getByte() { if (byteBuffer.remaining() < 1) { return -1; } @@ -426,6 +432,7 @@ public int getByte() throws IOException { private static final class StreamReader implements Reader { private final InputStream is; + // Motorola / big endian byte order. StreamReader(InputStream is) { this.is = is; diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java index 5647f6dcc5..51e9be79ac 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/Downsampler.java @@ -87,8 +87,7 @@ public final class Downsampler { *

This option is ignored unless we're on Android O+. */ public static final Option ALLOW_HARDWARE_CONFIG = - Option.memory( - "com.bumtpech.glide.load.resource.bitmap.Downsampler.AllowHardwareDecode", null); + Option.memory("com.bumtpech.glide.load.resource.bitmap.Downsampler.AllowHardwareDecode"); private static final String WBMP_MIME_TYPE = "image/vnd.wap.wbmp"; private static final String ICO_MIME_TYPE = "image/x-ico"; 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 ae2ef225dc..92855b5ba2 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 @@ -56,7 +56,8 @@ public static Resource obtain( } - private LazyBitmapDrawableResource(Resources resources, Resource bitmapResource) { + private LazyBitmapDrawableResource(@NonNull Resources resources, + @NonNull Resource bitmapResource) { this.resources = Preconditions.checkNotNull(resources); this.bitmapResource = Preconditions.checkNotNull(bitmapResource); } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream.java index aa21f9ce9b..c8139383f5 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream.java @@ -65,12 +65,12 @@ public class RecyclableBufferedInputStream extends FilterInputStream { private int pos; private final ArrayPool byteArrayPool; - public RecyclableBufferedInputStream(InputStream in, ArrayPool byteArrayPool) { + public RecyclableBufferedInputStream(@NonNull InputStream in, @NonNull ArrayPool byteArrayPool) { this(in, byteArrayPool, ArrayPool.STANDARD_BUFFER_SIZE_BYTES); } @VisibleForTesting - RecyclableBufferedInputStream(InputStream in, ArrayPool byteArrayPool, + RecyclableBufferedInputStream(@NonNull InputStream in, @NonNull ArrayPool byteArrayPool, int bufferSize) { super(in); this.byteArrayPool = byteArrayPool; diff --git a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoDecoder.java b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoDecoder.java index fb697b39bf..509e83e103 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoDecoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/bitmap/VideoDecoder.java @@ -53,8 +53,10 @@ public class VideoDecoder implements ResourceDecoder { "com.bumptech.glide.load.resource.bitmap.VideoBitmapDecode.TargetFrame", DEFAULT_FRAME, new Option.CacheKeyUpdater() { private final ByteBuffer buffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE); + @Override - public void update(byte[] keyBytes, Long value, MessageDigest messageDigest) { + public void update(@NonNull byte[] keyBytes, @NonNull Long value, + @NonNull MessageDigest messageDigest) { messageDigest.update(keyBytes); synchronized (buffer) { buffer.position(0); @@ -78,8 +80,11 @@ public void update(byte[] keyBytes, Long value, MessageDigest messageDigest) { /*defaultValue=*/ MediaMetadataRetriever.OPTION_CLOSEST_SYNC, new Option.CacheKeyUpdater() { private final ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE); + @Override - public void update(byte[] keyBytes, Integer value, MessageDigest messageDigest) { + public void update(@NonNull byte[] keyBytes, @NonNull Integer value, + @NonNull MessageDigest messageDigest) { + //noinspection ConstantConditions public API, people could have been doing it wrong if (value == null) { return; } @@ -175,10 +180,10 @@ private static Bitmap decodeFrame( // Target.SIZE_ORIGINAL is not used and not using getScaledFrameAtTime ever would match the // behavior of Glide in all versions of Android prior to OMR1, it's probably fine for now. if (Build.VERSION.SDK_INT >= VERSION_CODES.O_MR1 - && outWidth != Target.SIZE_ORIGINAL - && outHeight != Target.SIZE_ORIGINAL) { - return mediaMetadataRetriever.getScaledFrameAtTime( - frameTimeMicros, frameOption, outWidth, outHeight); + && outWidth != Target.SIZE_ORIGINAL + && outHeight != Target.SIZE_ORIGINAL) { + return mediaMetadataRetriever.getScaledFrameAtTime( + frameTimeMicros, frameOption, outWidth, outHeight); } else { return mediaMetadataRetriever.getFrameAtTime(frameTimeMicros, frameOption); } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawableEncoder.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawableEncoder.java index 8bd26919dd..e73f713dcc 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawableEncoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawableEncoder.java @@ -17,6 +17,7 @@ public class GifDrawableEncoder implements ResourceEncoder { private static final String TAG = "GifEncoder"; + @NonNull @Override public EncodeStrategy getEncodeStrategy(@NonNull Options options) { return EncodeStrategy.SOURCE; diff --git a/library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapBytesTranscoder.java b/library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapBytesTranscoder.java index 66f3f86e1c..9274b56ff4 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapBytesTranscoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapBytesTranscoder.java @@ -1,6 +1,8 @@ package com.bumptech.glide.load.resource.transcode; import android.graphics.Bitmap; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.engine.Resource; import com.bumptech.glide.load.resource.bytes.BytesResource; @@ -22,13 +24,15 @@ public BitmapBytesTranscoder() { // Public API. @SuppressWarnings("WeakerAccess") - public BitmapBytesTranscoder(Bitmap.CompressFormat compressFormat, int quality) { + public BitmapBytesTranscoder(@NonNull Bitmap.CompressFormat compressFormat, int quality) { this.compressFormat = compressFormat; this.quality = quality; } + @Nullable @Override - public Resource transcode(Resource toTranscode, Options options) { + public Resource transcode(@NonNull Resource toTranscode, + @NonNull Options options) { ByteArrayOutputStream os = new ByteArrayOutputStream(); toTranscode.get().compress(compressFormat, quality, os); toTranscode.recycle(); diff --git a/library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapDrawableTranscoder.java b/library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapDrawableTranscoder.java index a5a61ead99..b9dc68bb5e 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapDrawableTranscoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapDrawableTranscoder.java @@ -5,6 +5,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.engine.Resource; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; @@ -37,8 +38,10 @@ public BitmapDrawableTranscoder(@NonNull Resources resources) { this.resources = Preconditions.checkNotNull(resources); } + @Nullable @Override - public Resource transcode(Resource toTranscode, Options options) { + public Resource transcode(@NonNull Resource toTranscode, + @NonNull Options options) { return LazyBitmapDrawableResource.obtain(resources, toTranscode); } } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/transcode/DrawableBytesTranscoder.java b/library/src/main/java/com/bumptech/glide/load/resource/transcode/DrawableBytesTranscoder.java index 59be855f36..a37e16ff6b 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/transcode/DrawableBytesTranscoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/transcode/DrawableBytesTranscoder.java @@ -4,6 +4,7 @@ import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; 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.engine.Resource; @@ -15,17 +16,15 @@ * Obtains {@code byte[]} from {@link BitmapDrawable}s by delegating to a * {@link ResourceTranscoder} for {@link Bitmap}s to {@code byte[]}s. */ -public final class DrawableBytesTranscoder - implements ResourceTranscoder { - +public final class DrawableBytesTranscoder implements ResourceTranscoder { private final BitmapPool bitmapPool; private final ResourceTranscoder bitmapBytesTranscoder; private final ResourceTranscoder gifDrawableBytesTranscoder; public DrawableBytesTranscoder( - BitmapPool bitmapPool, - ResourceTranscoder bitmapBytesTranscoder, - ResourceTranscoder gifDrawableBytesTranscoder) { + @NonNull BitmapPool bitmapPool, + @NonNull ResourceTranscoder bitmapBytesTranscoder, + @NonNull ResourceTranscoder gifDrawableBytesTranscoder) { this.bitmapPool = bitmapPool; this.bitmapBytesTranscoder = bitmapBytesTranscoder; this.gifDrawableBytesTranscoder = gifDrawableBytesTranscoder; @@ -33,7 +32,8 @@ public DrawableBytesTranscoder( @Nullable @Override - public Resource transcode(Resource toTranscode, Options options) { + public Resource transcode(@NonNull Resource toTranscode, + @NonNull Options options) { Drawable drawable = toTranscode.get(); if (drawable instanceof BitmapDrawable) { return bitmapBytesTranscoder.transcode( @@ -45,7 +45,8 @@ public Resource transcode(Resource toTranscode, Options option } @SuppressWarnings("unchecked") - private static Resource toGifDrawableResource(Resource resource) { + @NonNull + private static Resource toGifDrawableResource(@NonNull Resource resource) { return (Resource) (Resource) resource; } } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/transcode/GifDrawableBytesTranscoder.java b/library/src/main/java/com/bumptech/glide/load/resource/transcode/GifDrawableBytesTranscoder.java index 0bc3c12b31..69e82202d4 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/transcode/GifDrawableBytesTranscoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/transcode/GifDrawableBytesTranscoder.java @@ -1,5 +1,7 @@ package com.bumptech.glide.load.resource.transcode; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.engine.Resource; import com.bumptech.glide.load.resource.bytes.BytesResource; @@ -13,8 +15,10 @@ * the GIF from the {@link com.bumptech.glide.load.resource.gif.GifDrawable}. */ public class GifDrawableBytesTranscoder implements ResourceTranscoder { + @Nullable @Override - public Resource transcode(Resource toTranscode, Options options) { + public Resource transcode(@NonNull Resource toTranscode, + @NonNull Options options) { GifDrawable gifData = toTranscode.get(); ByteBuffer byteBuffer = gifData.getBuffer(); return new BytesResource(ByteBufferUtil.toBytes(byteBuffer)); diff --git a/library/src/main/java/com/bumptech/glide/load/resource/transcode/ResourceTranscoder.java b/library/src/main/java/com/bumptech/glide/load/resource/transcode/ResourceTranscoder.java index e84bd6b000..fbd4631bd3 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/transcode/ResourceTranscoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/transcode/ResourceTranscoder.java @@ -1,5 +1,7 @@ package com.bumptech.glide.load.resource.transcode; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.engine.Resource; @@ -16,5 +18,6 @@ public interface ResourceTranscoder { * * @param toTranscode The resource to transcode. */ - Resource transcode(Resource toTranscode, Options options); + @Nullable + Resource transcode(@NonNull Resource toTranscode, @NonNull Options options); } diff --git a/library/src/main/java/com/bumptech/glide/load/resource/transcode/UnitTranscoder.java b/library/src/main/java/com/bumptech/glide/load/resource/transcode/UnitTranscoder.java index a52fb33b5d..45efdf5a1f 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/transcode/UnitTranscoder.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/transcode/UnitTranscoder.java @@ -1,5 +1,7 @@ package com.bumptech.glide.load.resource.transcode; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.engine.Resource; @@ -16,8 +18,9 @@ public static ResourceTranscoder get() { return (ResourceTranscoder) UNIT_TRANSCODER; } + @Nullable @Override - public Resource transcode(Resource toTranscode, Options options) { + public Resource transcode(@NonNull Resource toTranscode, @NonNull Options options) { return toTranscode; } } diff --git a/library/test/src/test/java/com/bumptech/glide/load/OptionsTest.java b/library/test/src/test/java/com/bumptech/glide/load/OptionsTest.java index eb45b43212..67ee5b1937 100644 --- a/library/test/src/test/java/com/bumptech/glide/load/OptionsTest.java +++ b/library/test/src/test/java/com/bumptech/glide/load/OptionsTest.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Option.CacheKeyUpdater; import com.bumptech.glide.tests.KeyTester; import java.nio.ByteBuffer; @@ -24,7 +25,8 @@ public void testEquals() { CacheKeyUpdater updater = new CacheKeyUpdater() { @Override - public void update(byte[] keyBytes, Integer value, MessageDigest messageDigest) { + public void update(@NonNull byte[] keyBytes, @NonNull Integer value, + @NonNull MessageDigest messageDigest) { messageDigest.update(keyBytes); messageDigest.update(ByteBuffer.allocate(4).putInt(value).array()); diff --git a/library/test/src/test/java/com/bumptech/glide/load/engine/EngineKeyTest.java b/library/test/src/test/java/com/bumptech/glide/load/engine/EngineKeyTest.java index 78c47be66b..f18a302895 100644 --- a/library/test/src/test/java/com/bumptech/glide/load/engine/EngineKeyTest.java +++ b/library/test/src/test/java/com/bumptech/glide/load/engine/EngineKeyTest.java @@ -1,5 +1,6 @@ package com.bumptech.glide.load.engine; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.Option; import com.bumptech.glide.load.Option.CacheKeyUpdater; @@ -55,7 +56,8 @@ public void testEqualsAndHashCode() { Options diskOptions = new Options(); diskOptions.set(Option.disk("key", new CacheKeyUpdater() { @Override - public void update(byte[] keyBytes, String value, MessageDigest messageDigest) { + public void update(@NonNull byte[] keyBytes, @NonNull String value, + @NonNull MessageDigest messageDigest) { messageDigest.update(keyBytes); messageDigest.update(value.getBytes(Key.CHARSET)); diff --git a/library/test/src/test/java/com/bumptech/glide/load/engine/ResourceCacheKeyTest.java b/library/test/src/test/java/com/bumptech/glide/load/engine/ResourceCacheKeyTest.java index f95935d852..bcefcbb1a9 100644 --- a/library/test/src/test/java/com/bumptech/glide/load/engine/ResourceCacheKeyTest.java +++ b/library/test/src/test/java/com/bumptech/glide/load/engine/ResourceCacheKeyTest.java @@ -3,6 +3,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; +import android.support.annotation.NonNull; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.Option; import com.bumptech.glide.load.Option.CacheKeyUpdater; @@ -13,7 +14,6 @@ import com.bumptech.glide.tests.KeyTester; import com.bumptech.glide.tests.Util; import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.util.Arrays; import org.junit.Before; import org.junit.Rule; @@ -45,21 +45,21 @@ public void setUp() { } @Test - public void testEqualsAndHashCode() throws NoSuchAlgorithmException { + public void testEqualsAndHashCode() { Options memoryOptions = new Options(); memoryOptions.set(Option.memory("key", new Object()), new Object()); Options diskOptions = new Options(); diskOptions.set(Option.disk("key", new CacheKeyUpdater() { @Override - public void update(byte[] keyBytes, String value, MessageDigest messageDigest) { + public void update(@NonNull byte[] keyBytes, @NonNull String value, + @NonNull MessageDigest messageDigest) { messageDigest.update(keyBytes); messageDigest.update(value.getBytes(Key.CHARSET)); } }), "value"); - for (int i = 0; i < 20; i++) { byte[] array = new byte[9]; Arrays.fill(array, (byte) 2); diff --git a/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgDrawableTranscoder.java b/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgDrawableTranscoder.java index 6b6b2ba1d9..a3fd80abfd 100644 --- a/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgDrawableTranscoder.java +++ b/samples/svg/src/main/java/com/bumptech/glide/samples/svg/SvgDrawableTranscoder.java @@ -2,6 +2,8 @@ import android.graphics.Picture; import android.graphics.drawable.PictureDrawable; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.bumptech.glide.load.Options; import com.bumptech.glide.load.engine.Resource; import com.bumptech.glide.load.resource.SimpleResource; @@ -13,12 +15,13 @@ * ({@link Picture}). */ public class SvgDrawableTranscoder implements ResourceTranscoder { + @Nullable @Override - public Resource transcode(Resource toTranscode, Options options) { + public Resource transcode(@NonNull Resource toTranscode, + @NonNull Options options) { SVG svg = toTranscode.get(); Picture picture = svg.renderToPicture(); PictureDrawable drawable = new PictureDrawable(picture); return new SimpleResource<>(drawable); } } -