From 68a570b4fea470a79fe5acd349697e7a8520f9d4 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 5 Feb 2014 20:04:13 +0100 Subject: [PATCH] Use WeakReference in MUC NodeInformationProvider MultiUserChat's NodeInformationProvider must not hold a strong reference to the Connection instance. Fixes SMACK-540. --- source/org/jivesoftware/smackx/muc/MultiUserChat.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/org/jivesoftware/smackx/muc/MultiUserChat.java b/source/org/jivesoftware/smackx/muc/MultiUserChat.java index db8a80f73..85d1aa8e1 100644 --- a/source/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/source/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -116,12 +117,16 @@ public class MultiUserChat { // Chat protocol. This information will be used when another client tries to // discover whether this client supports MUC or not. ServiceDiscoveryManager.getInstanceFor(connection).addFeature(discoNamespace); + // Set the NodeInformationProvider that will provide information about the // joined rooms whenever a disco request is received + final WeakReference weakRefConnection = new WeakReference(connection); ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider( discoNode, new NodeInformationProvider() { public List getNodeItems() { + Connection connection = weakRefConnection.get(); + if (connection == null) return new LinkedList(); List answer = new ArrayList(); Iterator rooms=MultiUserChat.getJoinedRooms(connection); while (rooms.hasNext()) {