From 4d87b4ee2db9295f48ec33e340fce1d3fc1641f2 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sat, 24 Jun 2023 20:58:53 -0500 Subject: [PATCH] Fix possible NPE --- .../siacs/conversations/persistance/FileBackend.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index c680cc823..b80cfc842 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -488,7 +488,7 @@ public class FileBackend { bitmap = withGifOverlay; } } - if (bitmap != null) { + if (key != null && bitmap != null) { cache.put(key, bitmap); } return bitmap; @@ -1121,7 +1121,7 @@ public class FileBackend { Bitmap blurhash = BlurHashDecoder.INSTANCE.decode(parts[1], r.width(), r.height(), 1.0f, false); if (blurhash != null) { cached = new BitmapDrawable(blurhash); - cache.put(parts[1], cached); + if (parts[1] != null && cached != null) cache.put(parts[1], cached); return cached; } } else if (parts[0].equals("image/thumbhash")) { @@ -1136,7 +1136,7 @@ public class FileBackend { pixels[i] = Color.argb(image.rgba[(i*4)+3] & 0xff, image.rgba[i*4] & 0xff, image.rgba[(i*4)+1] & 0xff, image.rgba[(i*4)+2] & 0xff); } cached = new BitmapDrawable(Bitmap.createBitmap(pixels, image.width, image.height, Bitmap.Config.ARGB_8888)); - cache.put(parts[1], cached); + if (parts[1] != null && cached != null) cache.put(parts[1], cached); return cached; } } @@ -1182,7 +1182,7 @@ public class FileBackend { decoder.setTargetSize(r.width(), r.height()); }); - if (thumbnail != null) { + if (thumbnail != null && file.getAbsolutePath() != null) { cache.put(file.getAbsolutePath(), thumbnail); return thumbnail; } @@ -1226,7 +1226,7 @@ public class FileBackend { throw new FileNotFoundException(); } } - cache.put(cacheKey, thumbnail); + if (cacheKey != null && thumbnail != null) cache.put(cacheKey, thumbnail); } } return thumbnail; -- 2.45.2