mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +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:
parent
5d963f7f9b
commit
47e327f2e6
1 changed files with 13 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue