Permalink
Browse files

Fix #5: NPE on BitmapLruCache.getFromDiskCache

  • Loading branch information...
1 parent ca75db4 commit 6f62e81360a93ad98b8ffbd8d59798b6a5857f87 @chrisbanes committed Feb 19, 2013
Showing with 6 additions and 4 deletions.
  1. +6 −4 library/src/uk/co/senab/bitmapcache/BitmapLruCache.java
@@ -127,7 +127,7 @@ private static String transformUrlForDiskCacheKey(String url) {
}
private DiskLruCache mDiskCache;
- private BitmapMemoryLruCache mMemoryCache;
+ private final BitmapMemoryLruCache mMemoryCache;
private final RecyclePolicy mRecyclePolicy;
@@ -217,7 +217,7 @@ public CacheableBitmapDrawable get(String url) {
* cache only.
*/
public CacheableBitmapDrawable get(String url, BitmapFactory.Options decodeOpts) {
- CacheableBitmapDrawable result = null;
+ CacheableBitmapDrawable result;
// First try Memory Cache
result = getFromMemoryCache(url);
@@ -260,8 +260,10 @@ public CacheableBitmapDrawable getFromDiskCache(final String url, final BitmapFa
if (null != bitmap) {
result = new CacheableBitmapDrawable(url, bitmap, mRecyclePolicy);
- mMemoryCache.put(result);
- } else {
+ if (null != mMemoryCache) {
+ mMemoryCache.put(result);
+ }
+ } else {
// If we get here, the file in the cache can't be
// decoded. Remove it and schedule a flush.
mDiskCache.remove(key);

0 comments on commit 6f62e81

Please sign in to comment.