From 3e8c1ee11761b012bfd61c954ba4957cdd942122 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 3 Jan 2020 22:50:27 +0100 Subject: [PATCH] Only modify and query downloads array in main thread This fixes a ConcurrentModificationException if the thread that queues downloads (database IO) adds the item to the downloads list and the notification updater queries the downloads list at the same time. --- .../core/service/download/DownloadService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 0be96d398..f7c338729 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -477,13 +477,13 @@ public class DownloadService extends Service { && isEnqueued(request, itemsEnqueued)) { request.setMediaEnqueued(true); } - downloads.add(downloader); - downloadExecutor.submit(downloader); - - postDownloaders(); + handler.post(() -> { + downloads.add(downloader); + downloadExecutor.submit(downloader); + postDownloaders(); + }); } - - queryDownloads(); + handler.post(this::queryDownloads); } private static boolean isEnqueued(@NonNull DownloadRequest request,