Prevent ConcurrentModificationException

Fixes #1351
This commit is contained in:
AsamK 2023-10-20 13:14:22 +02:00
parent 314159c273
commit 20f8fa2ebd

View file

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