diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2015-06-27 09:25:24 -0400 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2015-06-27 09:25:24 -0400 |
commit | d4fb1b09686cb998c850dc52abb9654e27bd31e9 (patch) | |
tree | 26098e357a5e2efbb295a448edbb50e74f1b9aec | |
parent | e332df4af572528f673745da2c7c13bf6ef43def (diff) | |
download | AntennaPod-d4fb1b09686cb998c850dc52abb9654e27bd31e9.zip |
Return a copy of the downloads.
This should prevent any IndexOutOfBounds errors
fixes AntennaPod/AntennaPod#968
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java | 7 |
1 files changed, 5 insertions, 2 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 03e323aa3..1ad4a9d0d 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 @@ -243,7 +243,7 @@ public class DownloadService extends Service { handler = new Handler(); newMediaFiles = Collections.synchronizedList(new ArrayList<Long>()); reportQueue = Collections.synchronizedList(new ArrayList<DownloadStatus>()); - downloads = new ArrayList<Downloader>(); + downloads = Collections.synchronizedList(new ArrayList<Downloader>()); numberOfDownloads = new AtomicInteger(0); IntentFilter cancelDownloadReceiverFilter = new IntentFilter(); @@ -1246,7 +1246,10 @@ public class DownloadService extends Service { } public List<Downloader> getDownloads() { - return downloads; + // return a copy of downloads, but the copy doesn't need to be synchronized. + synchronized (downloads) { + return new ArrayList<Downloader>(downloads); + } } } |