From 3f55eeb6ba3367862f753552805e80111602f6ac Mon Sep 17 00:00:00 2001 From: Elshad Seyidmammadov Date: Tue, 12 Sep 2023 13:38:09 +0400 Subject: [PATCH] Prevent NullPointerException in DownloadBroadcastReceiver When receiving a broadcast intent without a download ID or with an ID not found in the local map, the code attempted to access the 'callbackContext' on a null download cursor reference, leading to the exception. Check the download cursor and 'callbackContext' for null values to prevent this issue. --- src/android/com/pchab/android/plugin/Downloader.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/android/com/pchab/android/plugin/Downloader.java b/src/android/com/pchab/android/plugin/Downloader.java index 75e7bdc..dc5f657 100644 --- a/src/android/com/pchab/android/plugin/Downloader.java +++ b/src/android/com/pchab/android/plugin/Downloader.java @@ -135,6 +135,9 @@ public void onReceive( Context context, Intent intent) { //Retrieve the saved download Download currentDownload = downloadMap.get(downloadId); downloadMap.remove(downloadId); + if(currentDownload == null || currentDownload.callbackContext == null) { + return; + } int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = cursor.getInt(columnIndex);