fix ConcurrentModificationException when notification arrives

This commit is contained in:
Conny Duck 2017-12-02 14:34:47 +01:00
parent c7ecf352cf
commit ab4525ac38
1 changed files with 4 additions and 2 deletions

View File

@ -33,6 +33,7 @@ import com.keylesspalace.tusky.util.NotificationManager;
import com.keylesspalace.tusky.util.OkHttpUtils; import com.keylesspalace.tusky.util.OkHttpUtils;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -124,8 +125,9 @@ public final class NotificationPullJobCreator implements JobCreator {
private void onNotificationsReceived(List<Notification> notificationList) { private void onNotificationsReceived(List<Notification> notificationList) {
SharedPreferences notificationsPreferences = context.getSharedPreferences( SharedPreferences notificationsPreferences = context.getSharedPreferences(
"Notifications", Context.MODE_PRIVATE); "Notifications", Context.MODE_PRIVATE);
Set<String> currentIds = notificationsPreferences.getStringSet( //make a copy of the string set, the returned instance should not be modified
"current_ids", new HashSet<String>()); Set<String> currentIds = new HashSet<>(notificationsPreferences.getStringSet(
"current_ids", Collections.emptySet()));
for (Notification notification : notificationList) { for (Notification notification : notificationList) {
String id = notification.id; String id = notification.id;
if (!currentIds.contains(id)) { if (!currentIds.contains(id)) {