1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-23 04:57:58 +01: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.
*/
public synchronized MultiUserChat getMultiUserChat(String jid) {
MultiUserChat multiUserChat = multiUserChats.get(jid).get();
if (multiUserChat == null) {
multiUserChat = new MultiUserChat(connection(), jid, this);
multiUserChats.put(jid, new WeakReference<MultiUserChat>(multiUserChat));
WeakReference<MultiUserChat> weakRefMultiUserChat = multiUserChats.get(jid);
if (weakRefMultiUserChat == null) {
return createNewMucAndAddToMap(jid);
}
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;
}