mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 08:12: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.
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue