]> nmode's Git Repositories - signal-cli/commitdiff
Prevent ConcurrentModificationException
authorAsamK <asamk@gmx.de>
Fri, 20 Oct 2023 11:14:22 +0000 (13:14 +0200)
committerAsamK <asamk@gmx.de>
Sun, 22 Oct 2023 18:42:25 +0000 (20:42 +0200)
Fixes #1351

lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java

index 44c0bafaa4fbb786b2124759dbb34a25d971a8db..87e5f3d2abe7e737d74d0e3d66d02e655e6d6377 100644 (file)
@@ -435,10 +435,7 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
     public void deleteRecipientData(RecipientId recipientId) {
         logger.debug("Deleting recipient data for {}", recipientId);
         synchronized (recipientsLock) {
-            recipientAddressCache.entrySet()
-                    .stream()
-                    .filter(e -> e.getValue().id().equals(recipientId))
-                    .forEach(e -> recipientAddressCache.remove(e.getKey()));
+            recipientAddressCache.entrySet().removeIf(e -> e.getValue().id().equals(recipientId));
             try (final var connection = database.getConnection()) {
                 connection.setAutoCommit(false);
                 storeContact(connection, recipientId, null);
@@ -708,10 +705,7 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
                     recipientMergeHandler.mergeRecipients(connection, pair.first(), toBeMergedRecipientId);
                     deleteRecipient(connection, toBeMergedRecipientId);
                     synchronized (recipientsLock) {
-                        recipientAddressCache.entrySet()
-                                .stream()
-                                .filter(e -> e.getValue().id().equals(toBeMergedRecipientId))
-                                .forEach(e -> recipientAddressCache.remove(e.getKey()));
+                        recipientAddressCache.entrySet().removeIf(e -> e.getValue().id().equals(toBeMergedRecipientId));
                     }
                 }
             } catch (SQLException e) {
@@ -807,10 +801,7 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
 
     private void removeRecipientAddress(Connection connection, RecipientId recipientId) throws SQLException {
         synchronized (recipientsLock) {
-            recipientAddressCache.entrySet()
-                    .stream()
-                    .filter(e -> e.getValue().id().equals(recipientId))
-                    .forEach(e -> recipientAddressCache.remove(e.getKey()));
+            recipientAddressCache.entrySet().removeIf(e -> e.getValue().id().equals(recipientId));
             final var sql = (
                     """
                     UPDATE %s
@@ -829,10 +820,7 @@ public class RecipientStore implements RecipientIdCreator, RecipientResolver, Re
             Connection connection, RecipientId recipientId, final RecipientAddress address
     ) throws SQLException {
         synchronized (recipientsLock) {
-            recipientAddressCache.entrySet()
-                    .stream()
-                    .filter(e -> e.getValue().id().equals(recipientId))
-                    .forEach(e -> recipientAddressCache.remove(e.getKey()));
+            recipientAddressCache.entrySet().removeIf(e -> e.getValue().id().equals(recipientId));
             final var sql = (
                     """
                     UPDATE %s