From fd1ab475a30e83d0abfbfe77261677989d175aeb 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 0ea4e69e..4fe10bc8 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)) {