From a82bb9369725808151b042ed32d31a3404eb7155 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Tue, 4 Nov 2014 13:12:08 +0200 Subject: Fixes possible NPE if OperationSetMultiUserChat is disabled for xmpp provider. --- .../IncomingFileTransferRequestJabberImpl.java | 11 +++++---- ...perationSetBasicInstantMessagingJabberImpl.java | 26 +++++++++++----------- .../OperationSetBasicTelephonyJabberImpl.java | 9 +++++--- .../jabber/OperationSetFileTransferJabberImpl.java | 6 +++-- .../OperationSetPersistentPresenceJabberImpl.java | 20 ++++++++++------- ...perationSetTelephonyConferencingJabberImpl.java | 3 ++- .../OperationSetTypingNotificationsJabberImpl.java | 20 ++++++++++------- .../protocol/jabber/VolatileContactJabberImpl.java | 19 +++++++++++----- 8 files changed, 69 insertions(+), 45 deletions(-) (limited to 'src/net/java') diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/IncomingFileTransferRequestJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/IncomingFileTransferRequestJabberImpl.java index f8e2acd..e57e8ca 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/IncomingFileTransferRequestJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/IncomingFileTransferRequestJabberImpl.java @@ -81,10 +81,13 @@ public class IncomingFileTransferRequestJabberImpl sender = opSetPersPresence.findContactByID(fromUserID); if(sender == null) { - ChatRoom privateContactRoom - = ((OperationSetMultiUserChatJabberImpl) - jabberProvider.getOperationSet( - OperationSetMultiUserChat.class)) + ChatRoom privateContactRoom = null; + OperationSetMultiUserChatJabberImpl mucOpSet = + (OperationSetMultiUserChatJabberImpl)jabberProvider + .getOperationSet(OperationSetMultiUserChat.class); + + if(mucOpSet != null) + privateContactRoom = mucOpSet .getChatRoom(StringUtils.parseBareAddress(fromUserID)); if(privateContactRoom != null) { diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java index 486d49f..c889981 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java @@ -299,7 +299,7 @@ public class OperationSetBasicInstantMessagingJabberImpl * activity (i.e. neither outgoing nor incoming messags) for more than * JID_INACTIVITY_TIMEOUT. Note that this method is not synchronous and that * it is only meant for use by the {@link #getThreadIDForAddress(String)} and - * {@link #putJidForAddress(String, String, Chat)} + * {@link #putJidForAddress(String, String)} */ private void purgeOldJids() { @@ -327,7 +327,7 @@ public class OperationSetBasicInstantMessagingJabberImpl * entries that haven't seen any activity (i.e. no one has tried to get or * remap it) for a delay longer than JID_INACTIVITY_TIMEOUT. * - * @param address the address that we'd like to obtain a jid for. + * @param jid the jid that we'd like to obtain a threadID for. * * @return the last jid that the party with the specified address * contacted us from or null if we don't have a jid for the @@ -355,8 +355,7 @@ public class OperationSetBasicInstantMessagingJabberImpl * the specified address to the jid that they last * contacted us from. * - * @param address the bare address (i.e. no resource included) of the - * contact that we'd like to set a jid for. + * @param threadID the threadID of conversation. * @param jid the jid (i.e. address/resource) that the contact with the * specified address last contacted us from. */ @@ -494,10 +493,7 @@ public class OperationSetBasicInstantMessagingJabberImpl putJidForAddress(toJID, threadID); } - MessageDeliveredEvent msgDeliveredEvt = - new MessageDeliveredEvent(message, to, toResource); - - return msgDeliveredEvt; + return new MessageDeliveredEvent(message, to, toResource); } /** @@ -815,9 +811,13 @@ public class OperationSetBasicInstantMessagingJabberImpl String userBareID = StringUtils.parseBareAddress(userFullId); boolean isPrivateMessaging = false; - ChatRoom privateContactRoom = ((OperationSetMultiUserChatJabberImpl) - jabberProvider.getOperationSet(OperationSetMultiUserChat.class)) - .getChatRoom(userBareID); + ChatRoom privateContactRoom = null; + OperationSetMultiUserChatJabberImpl mucOpSet = + (OperationSetMultiUserChatJabberImpl)jabberProvider + .getOperationSet(OperationSetMultiUserChat.class); + if(mucOpSet != null) + privateContactRoom = mucOpSet.getChatRoom(userBareID); + if(privateContactRoom != null) { isPrivateMessaging = true; @@ -1128,7 +1128,7 @@ public class OperationSetBasicInstantMessagingJabberImpl Integer.toString( threadCount )//{2} - thread count }); - StringBuffer message = new StringBuffer(newMailHeader); + StringBuilder message = new StringBuilder(newMailHeader); //we now start an html table for the threads. message.append(" chatRooms = parentProvider.getOperationSet( - OperationSetMultiUserChat.class) - .getCurrentlyJoinedChatRooms(); - for(ChatRoom chatRoom : chatRooms) + OperationSetMultiUserChat mucOpSet = + parentProvider.getOperationSet( + OperationSetMultiUserChat.class); + if(mucOpSet != null) { - if(chatRoom.getName().equals(userID)) + List chatRooms + = mucOpSet.getCurrentlyJoinedChatRooms(); + for(ChatRoom chatRoom : chatRooms) { - userID = presence.getFrom(); - break; + if(chatRoom.getName().equals(userID)) + { + userID = presence.getFrom(); + break; + } } } - if (logger.isDebugEnabled()) logger.debug("Received a status update for buddy=" + userID); diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTelephonyConferencingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTelephonyConferencingJabberImpl.java index 175802c..e70cfbd 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTelephonyConferencingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTelephonyConferencingJabberImpl.java @@ -487,7 +487,8 @@ public class OperationSetTelephonyConferencingJabberImpl = (OperationSetMultiUserChatJabberImpl) parentProvider.getOperationSet(OperationSetMultiUserChat.class); ChatRoom room = null; - room = opSetMUC.getChatRoom(chatRoomName); + if(opSetMUC != null) + room = opSetMUC.getChatRoom(chatRoomName); if(room != null) return "xmpp:" + chatRoomName + "/" + room.getUserNickname(); diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java index 2e43512..590ca9f 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTypingNotificationsJabberImpl.java @@ -163,7 +163,7 @@ public class OperationSetTypingNotificationsJabberImpl + " to " + toJID); - ChatState chatState = null; + ChatState chatState; if(state == STATE_TYPING) { @@ -395,7 +395,6 @@ public class OperationSetTypingNotificationsJabberImpl /** * Called by smack when the state of a chat changes. * - * @param chat the chat that is concerned by this event. * @param state the new state of the chat. * @param message the message containing the new chat state */ @@ -410,15 +409,20 @@ public class OperationSetTypingNotificationsJabberImpl String fromID = StringUtils.parseBareAddress(fromJID); - List chatRooms = parentProvider.getOperationSet( - OperationSetMultiUserChat.class).getCurrentlyJoinedChatRooms(); boolean isPrivateMessagingAddress = false; - for(ChatRoom chatRoom : chatRooms) + OperationSetMultiUserChat mucOpSet = parentProvider + .getOperationSet(OperationSetMultiUserChat.class); + if(mucOpSet != null) { - if(chatRoom.getName().equals(fromID)) + List chatRooms + = mucOpSet.getCurrentlyJoinedChatRooms(); + for(ChatRoom chatRoom : chatRooms) { - isPrivateMessagingAddress = true; - break; + if(chatRoom.getName().equals(fromID)) + { + isPrivateMessagingAddress = true; + break; + } } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/VolatileContactJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/VolatileContactJabberImpl.java index a5ee940..42e3d45 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/VolatileContactJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/VolatileContactJabberImpl.java @@ -169,12 +169,19 @@ public class VolatileContactJabberImpl { if(!isPrivateMessagingContact) return getAddress(); - ChatRoomMemberJabberImpl chatRoomMember - = ((OperationSetMultiUserChatJabberImpl)getProtocolProvider() - .getOperationSet(OperationSetMultiUserChat.class)) - .getChatRoom(StringUtils.parseBareAddress(contactId)) - .findMemberForNickName( - StringUtils.parseResource(contactId)); + + + ChatRoomMemberJabberImpl chatRoomMember = null; + OperationSetMultiUserChatJabberImpl mucOpSet = + (OperationSetMultiUserChatJabberImpl)getProtocolProvider() + .getOperationSet(OperationSetMultiUserChat.class); + if(mucOpSet != null) + { + chatRoomMember = mucOpSet + .getChatRoom(StringUtils.parseBareAddress(contactId)) + .findMemberForNickName( + StringUtils.parseResource(contactId)); + } return ((chatRoomMember == null)? null : StringUtils.parseBareAddress( chatRoomMember.getJabberID())); } -- cgit v1.1