diff --git a/components/net/sf/briar/db/DatabaseComponentImpl.java b/components/net/sf/briar/db/DatabaseComponentImpl.java index 92420cca1..56b9f8253 100644 --- a/components/net/sf/briar/db/DatabaseComponentImpl.java +++ b/components/net/sf/briar/db/DatabaseComponentImpl.java @@ -198,14 +198,15 @@ DatabaseCleaner.Callback { /** Notifies all listeners of a database event. */ private void callListeners(DatabaseEvent e) { + List copy; synchronized(listeners) { - if(!listeners.isEmpty()) { - // Shuffle the listeners so we don't always send new messages - // to contacts in the same order - Collections.shuffle(listeners); - for(DatabaseListener d : listeners) d.eventOccurred(e); - } + if(listeners.isEmpty()) return; + copy = new ArrayList(listeners); } + // Shuffle the listeners so we don't always send new messages + // to contacts in the same order + Collections.shuffle(copy); + for(DatabaseListener d : copy) d.eventOccurred(e); } public void addLocalGroupMessage(Message m) throws DbException {