diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java index c16da54168..664db4353d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/LiveRecipientCache.java @@ -113,6 +113,7 @@ public final class LiveRecipientCache { newRecipients.stream().filter(this::isValidForCache).forEach(recipient -> { LiveRecipient live; boolean needsResolve; + boolean needsSet = false; synchronized (recipients) { live = recipients.get(recipient.getId()); @@ -122,13 +123,18 @@ public final class LiveRecipientCache { recipients.put(recipient.getId(), live); needsResolve = recipient.isResolving(); } else if (live.get().isResolving() || !recipient.isResolving()) { - live.set(recipient); + needsSet = true; needsResolve = recipient.isResolving(); } else { needsResolve = false; } } + // This requires taking another lock, so we move it out of the critical section above + if (needsSet) { + live.set(recipient); + } + if (needsResolve) { LiveRecipient toResolve = live;