1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-18 09:24:49 +02:00

Fix NPE in MultiUserChatManager.getMultiUserchat()

Since the HashMap has WeakReferences as values, there are two levels at
which values could be null.
This commit is contained in:
Florian Schmaus 2014-10-20 21:12:51 +02:00
parent 5d963f7f9b
commit 47e327f2e6

View file

@ -150,11 +150,20 @@ public class MultiUserChatManager extends Manager {
* multi-user chat service is running. Make sure to provide a valid JID. * multi-user chat service is running. Make sure to provide a valid JID.
*/ */
public synchronized MultiUserChat getMultiUserChat(String jid) { public synchronized MultiUserChat getMultiUserChat(String jid) {
MultiUserChat multiUserChat = multiUserChats.get(jid).get(); WeakReference<MultiUserChat> weakRefMultiUserChat = multiUserChats.get(jid);
if (multiUserChat == null) { if (weakRefMultiUserChat == null) {
multiUserChat = new MultiUserChat(connection(), jid, this); return createNewMucAndAddToMap(jid);
multiUserChats.put(jid, new WeakReference<MultiUserChat>(multiUserChat));
} }
MultiUserChat multiUserChat = weakRefMultiUserChat.get();
if (multiUserChat == null) {
return createNewMucAndAddToMap(jid);
}
return multiUserChat;
}
private MultiUserChat createNewMucAndAddToMap(String jid) {
MultiUserChat multiUserChat = new MultiUserChat(connection(), jid, this);
multiUserChats.put(jid, new WeakReference<MultiUserChat>(multiUserChat));
return multiUserChat; return multiUserChat;
} }