From ab4525ac38f42089ccd7105e0c377a3cab72b36d Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Sat, 2 Dec 2017 14:34:47 +0100 Subject: [PATCH] fix ConcurrentModificationException when notification arrives --- .../com/keylesspalace/tusky/NotificationPullJobCreator.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java b/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java index 0ea4e69e7..4fe10bc8f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java +++ b/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java @@ -33,6 +33,7 @@ import com.keylesspalace.tusky.util.NotificationManager; import com.keylesspalace.tusky.util.OkHttpUtils; import java.io.IOException; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -124,8 +125,9 @@ public final class NotificationPullJobCreator implements JobCreator { private void onNotificationsReceived(List notificationList) { SharedPreferences notificationsPreferences = context.getSharedPreferences( "Notifications", Context.MODE_PRIVATE); - Set currentIds = notificationsPreferences.getStringSet( - "current_ids", new HashSet()); + //make a copy of the string set, the returned instance should not be modified + Set currentIds = new HashSet<>(notificationsPreferences.getStringSet( + "current_ids", Collections.emptySet())); for (Notification notification : notificationList) { String id = notification.id; if (!currentIds.contains(id)) {