From 20f8fa2ebd80dd8828db349b530f25e8274ff74e Mon Sep 17 00:00:00 2001 From: AsamK Date: Fri, 20 Oct 2023 13:14:22 +0200 Subject: [PATCH] Prevent ConcurrentModificationException Fixes #1351 --- .../storage/recipients/RecipientStore.java | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java index 44c0bafa..87e5f3d2 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/recipients/RecipientStore.java @@ -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 -- 2.50.1