From a58bbe19e219562299f8a981038c893319b6d1ca Mon Sep 17 00:00:00 2001 From: Courville Software Date: Sat, 25 May 2024 00:03:15 +0200 Subject: [PATCH] Blacklist: avoid NPE --- .../archos/mediaprovider/video/Blacklist.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/com/archos/mediaprovider/video/Blacklist.java b/src/com/archos/mediaprovider/video/Blacklist.java index ae931f18..c65e09b7 100644 --- a/src/com/archos/mediaprovider/video/Blacklist.java +++ b/src/com/archos/mediaprovider/video/Blacklist.java @@ -132,26 +132,30 @@ public boolean isFilenameBlacklisted(String fileName) { // check if fileName con private static ArrayList getBlacklisteds() { ArrayList blacklisteds = new ArrayList<>(); Cursor c = BlacklistedDbAdapter.VIDEO.queryAllBlacklisteds(mContext); - final int pathColumn = c.getColumnIndexOrThrow(BlacklistedDbAdapter.KEY_PATH); - try { - if (c.moveToFirst()) { - while (!c.isAfterLast()) { - String blacklistedPath = c.getString(pathColumn); - if (blacklistedPath != null) { - blacklistedPath = Uri.parse(blacklistedPath).getPath(); - if (!blacklistedPath.endsWith("/")) - blacklistedPath += "/"; - blacklisteds.add(blacklistedPath); + if (c != null) { + final int pathColumn = c.getColumnIndexOrThrow(BlacklistedDbAdapter.KEY_PATH); + try { + if (c.moveToFirst()) { + while (!c.isAfterLast()) { + String blacklistedPath = c.getString(pathColumn); + if (blacklistedPath != null) { + blacklistedPath = Uri.parse(blacklistedPath).getPath(); + if (!blacklistedPath.endsWith("/")) + blacklistedPath += "/"; + blacklisteds.add(blacklistedPath); + } + c.moveToNext(); } - c.moveToNext(); } + } catch (Exception e) { + // with c.close() we get with c.moveToFirst() IllegalStateException: Cannot perform this operation because the connection pool has been closed + // without c.close() we get with c.moveToFirst() CursorWindowAllocationException + Log.e(TAG, "getBlacklisteds: caught Exception", e); + } finally { + c.close(); } - } catch (Exception e) { - // with c.close() we get with c.moveToFirst() IllegalStateException: Cannot perform this operation because the connection pool has been closed - // without c.close() we get with c.moveToFirst() CursorWindowAllocationException - Log.e(TAG, "getBlacklisteds: caught Exception", e); - } finally { - c.close(); + } else { + Log.e(TAG, "getBlacklisteds: cursor is null!"); } return blacklisteds; }