1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-22 18:48:00 +01:00

ChatManager should not throw a NPE if 'from' is null

Fixes SMACK-551
This commit is contained in:
Florian Schmaus 2014-03-18 08:44:03 +01:00
parent ec82f63191
commit 81d49d2f60

View file

@ -149,6 +149,9 @@ public class ChatManager extends Manager{
if(chat == null) {
chat = createChat(message);
}
// The chat could not be created, abort here
if (chat == null)
return;
deliverMessage(chat, message);
}
}, filter);
@ -245,12 +248,24 @@ public class ChatManager extends Manager{
baseJidChats.remove(StringUtils.parseBareAddress(userJID));
}
/**
* Creates a new {@link Chat} based on the message. May returns null if no chat could be
* created, e.g. because the message comes without from.
*
* @param message
* @return a Chat or null if none can be created
*/
private Chat createChat(Message message) {
String userJID = message.getFrom();
// According to RFC6120 8.1.2.1 4. messages without a 'from' attribute are valid, but they
// are of no use in this case for ChatManager
if (userJID == null) {
return null;
}
String threadID = message.getThread();
if(threadID == null) {
threadID = nextID();
}
String userJID = message.getFrom();
return createChat(userJID, threadID, false);
}
@ -268,7 +283,11 @@ public class ChatManager extends Manager{
if (matchMode == MatchMode.NONE) {
return null;
}
// According to RFC6120 8.1.2.1 4. messages without a 'from' attribute are valid, but they
// are of no use in this case for ChatManager
if (userJID == null) {
return null;
}
Chat match = jidChats.get(userJID);
if (match == null && (matchMode == MatchMode.BARE_JID)) {