From 8de81e0bc8a0ec777cede0c9d19fdf1a8dad4db2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 11 Jul 2017 23:09:51 +0200 Subject: [PATCH] sync around Conversation.getLatestMessage() --- .../conversations/entities/Conversation.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index aee51cdc3..acd18e07f 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -470,13 +470,15 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public Message getLatestMessage() { - if (this.messages.size() == 0) { - Message message = new Message(this, "", Message.ENCRYPTION_NONE); - message.setType(Message.TYPE_STATUS); - message.setTime(Math.max(getCreated(),getLastClearHistory().getTimestamp())); - return message; - } else { - return this.messages.get(this.messages.size() - 1); + synchronized (this.messages) { + if (this.messages.size() == 0) { + Message message = new Message(this, "", Message.ENCRYPTION_NONE); + message.setType(Message.TYPE_STATUS); + message.setTime(Math.max(getCreated(), getLastClearHistory().getTimestamp())); + return message; + } else { + return this.messages.get(this.messages.size() - 1); + } } }