[Android] Bitmap cache: prevent NPE
Geoffrey Métais
git at videolan.org
Mon May 27 11:42:10 CEST 2019
vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 27 09:51:36 2019 +0200| [c6c1d4da2de7eb99343f7b0b4a6eb09beed25758] | committer: Geoffrey Métais
Bitmap cache: prevent NPE
> https://code.videolan.org/videolan/vlc-android/commit/c6c1d4da2de7eb99343f7b0b4a6eb09beed25758
---
vlc-android/src/org/videolan/vlc/gui/helpers/BitmapCache.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapCache.java b/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapCache.java
index 66f8b27cc..0a7995924 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapCache.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/BitmapCache.java
@@ -25,9 +25,10 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
-import androidx.collection.LruCache;
import android.util.Log;
+import androidx.collection.LruCache;
+
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.util.Strings;
@@ -63,6 +64,7 @@ public class BitmapCache {
}
public synchronized Bitmap getBitmapFromMemCache(String key) {
+ if (mMemCache == null || key == null) return null;
final Bitmap b = mMemCache.get(key);
if (b == null){
mMemCache.remove(key);
@@ -72,6 +74,7 @@ public class BitmapCache {
}
public synchronized void addBitmapToMemCache(String key, Bitmap bitmap) {
+ if (mMemCache == null) return ;
if (key != null && bitmap != null && getBitmapFromMemCache(key) == null) {
mMemCache.put(key, bitmap);
}
@@ -86,7 +89,7 @@ public class BitmapCache {
}
public synchronized void clear() {
- mMemCache.evictAll();
+ if (mMemCache != null) mMemCache.evictAll();
}
public static Bitmap getFromResource(Resources res, int resId) {
More information about the Android
mailing list