From d8d1c1192f6473e571d5536250b091293783b334 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 9 Aug 2017 09:43:41 +0200 Subject: [PATCH] code cleanup and synchronized getMarkableMessage() --- .../siacs/conversations/entities/Conversation.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index acd18e07f..1d48438f3 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -456,15 +456,13 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public Message getLatestMarkableMessage() { - for (int i = this.messages.size() - 1; i >= 0; --i) { - if (this.messages.get(i).getStatus() <= Message.STATUS_RECEIVED - && this.messages.get(i).markable) { - if (this.messages.get(i).isRead()) { - return null; - } else { - return this.messages.get(i); + synchronized (this.messages) { + for (int i = this.messages.size() - 1; i >= 0; --i) { + final Message message = this.messages.get(i); + if (message.getStatus() <= Message.STATUS_RECEIVED && message.markable) { + return message.isRead() ? null : message; } - } + } } return null; }