From d92bbb13a2f4ca98ce52fa8110082fab6f970d3d Mon Sep 17 00:00:00 2001 From: Vincent Lucas Date: Tue, 20 Mar 2012 13:24:17 +0000 Subject: [PATCH] Corrects a null pointeur exception, which occurs while trying to check the current avatar image for a contact not yet in the contact list. --- ...rationSetPersistentPresenceJabberImpl.java | 91 +++++++++++-------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java index 56ebf8423..b40c67cd8 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetPersistentPresenceJabberImpl.java @@ -1409,6 +1409,16 @@ public void parseContactPhotoPresence(Packet packet) = StringUtils.parseBareAddress(packet.getFrom()); ContactJabberImpl sourceContact = ssContactList.findContactById(userID); + + /** + * If this contact is not yet in our contact list, then there is no need + * to manage this photo update. + */ + if(sourceContact == null) + { + return; + } + byte[] currentAvatar = sourceContact.getImage(false); // Get the packet extension which contains the photo tag. @@ -1416,50 +1426,53 @@ public void parseContactPhotoPresence(Packet packet) (DefaultPacketExtension) packet.getExtension( VCardTempXUpdatePresenceExtension.ELEMENT_NAME, VCardTempXUpdatePresenceExtension.NAMESPACE); - try + if(defaultPacketExtension != null) { - String packetPhotoSHA1 = defaultPacketExtension.getValue("photo"); - // If this presence packet has a photo tag with a SHA-1 hash which - // differs from the current avatar SHA-1 hash, then Jitsi retreives - // the new avatar image and updates this contact image in the - // contact list. - if(defaultPacketExtension != null - && packetPhotoSHA1 != null - && !packetPhotoSHA1.equals( - VCardTempXUpdatePresenceExtension.getImageSha1( - currentAvatar)) - ) + try { - byte[] newAvatar = null; - - // If there is an avatar image, retreives it. - if(packetPhotoSHA1.length() != 0) - { - // Retrieves the new contact avatar image. - VCard vCard = new VCard(); - vCard.load(parentProvider.getConnection(), userID); - newAvatar = vCard.getAvatar(); - } - // Else removes the current avatar image, since the contact has - // removed it from the server. - else + String packetPhotoSHA1 = + defaultPacketExtension.getValue("photo"); + // If this presence packet has a photo tag with a SHA-1 hash + // which differs from the current avatar SHA-1 hash, then Jitsi + // retreives the new avatar image and updates this contact image + // in the contact list. + if(packetPhotoSHA1 != null + && !packetPhotoSHA1.equals( + VCardTempXUpdatePresenceExtension.getImageSha1( + currentAvatar)) + ) { - newAvatar = new byte[0]; - } + byte[] newAvatar = null; + + // If there is an avatar image, retreives it. + if(packetPhotoSHA1.length() != 0) + { + // Retrieves the new contact avatar image. + VCard vCard = new VCard(); + vCard.load(parentProvider.getConnection(), userID); + newAvatar = vCard.getAvatar(); + } + // Else removes the current avatar image, since the contact + // has removed it from the server. + else + { + newAvatar = new byte[0]; + } - // Sets the new avatar image to the Jitsi contact. - sourceContact.setImage(newAvatar); - // Fires a property change event to update the contact list. - this.fireContactPropertyChangeEvent( - ContactPropertyChangeEvent.PROPERTY_IMAGE, - sourceContact, - currentAvatar, - newAvatar); + // Sets the new avatar image to the Jitsi contact. + sourceContact.setImage(newAvatar); + // Fires a property change event to update the contact list. + this.fireContactPropertyChangeEvent( + ContactPropertyChangeEvent.PROPERTY_IMAGE, + sourceContact, + currentAvatar, + newAvatar); + } + } + catch(XMPPException ex) + { + logger.info("Can not retrieve vCard from: " + packet.getFrom(), ex); } - } - catch(XMPPException ex) - { - logger.info("Can not retrieve vCard from: " + packet.getFrom(), ex); } } }