Program: 103073
Project: 103073
Buggy source:
/** 
 * Updates the resources for the contact.
 * @param contact the contact which resources to update.
 * @param removeUnavailable whether to remove unavailable resources.
 */
private void updateResources(ContactJabberImpl contact,boolean removeUnavailable){
  if (!contact.isResolved() || (contact instanceof VolatileContactJabberImpl && ((VolatileContactJabberImpl)contact).isPrivateMessagingContact()))   return;
  Map<String,ContactResourceJabberImpl> resources=contact.getResourcesMap();
  Iterator<Presence> it=parentProvider.getConnection().getRoster().getPresences(contact.getAddress());
  while (it.hasNext()) {
    Presence presence=it.next();
    String resource=StringUtils.parseResource(presence.getFrom());
    if (resource != null && resource.length() > 0) {
      String fullJid=presence.getFrom();
      ContactResourceJabberImpl contactResource=resources.get(fullJid);
      PresenceStatus newPresenceStatus=OperationSetPersistentPresenceJabberImpl.jabberStatusToPresenceStatus(presence,parentProvider);
      if (contactResource == null) {
        contactResource=new ContactResourceJabberImpl(fullJid,contact,resource,newPresenceStatus,presence.getPriority(),mobileIndicator.isMobileResource(resource,fullJid));
        resources.put(fullJid,contactResource);
        contact.fireContactResourceEvent(new ContactResourceEvent(contact,contactResource,ContactResourceEvent.RESOURCE_ADDED));
      }
 else {
        if (contactResource.getPresenceStatus().getStatus() != newPresenceStatus.getStatus()) {
          contactResource.setPresenceStatus(newPresenceStatus);
          contact.fireContactResourceEvent(new ContactResourceEvent(contact,contactResource,ContactResourceEvent.RESOURCE_MODIFIED));
        }
      }
    }
  }
  if (!removeUnavailable)   return;
  Iterator<String> resourceIter=resources.keySet().iterator();
  while (resourceIter.hasNext()) {
    String fullJid=resourceIter.next();
    if (!parentProvider.getConnection().getRoster().getPresenceResource(fullJid).isAvailable()) {
      ContactResource removedResource=resources.get(fullJid);
      if (resources.containsKey(fullJid)) {
        resources.remove(fullJid);
        contact.fireContactResourceEvent(new ContactResourceEvent(contact,removedResource,ContactResourceEvent.RESOURCE_REMOVED));
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Updates the resources for the contact.
 * @param contact the contact which resources to update.
 * @param removeUnavailable whether to remove unavailable resources.
 */
private void updateResources(ContactJabberImpl contact,boolean removeUnavailable){
  if (!contact.isResolved() || (contact instanceof VolatileContactJabberImpl && ((VolatileContactJabberImpl)contact).isPrivateMessagingContact()))   return;
  Map<String,ContactResourceJabberImpl> resources=contact.getResourcesMap();
  Iterator<Presence> it=parentProvider.getConnection().getRoster().getPresences(contact.getAddress());
  while (it.hasNext()) {
    Presence presence=it.next();
    String resource=StringUtils.parseResource(presence.getFrom());
    if (resource != null && resource.length() > 0) {
      String fullJid=presence.getFrom();
      ContactResourceJabberImpl contactResource=resources.get(fullJid);
      PresenceStatus newPresenceStatus=OperationSetPersistentPresenceJabberImpl.jabberStatusToPresenceStatus(presence,parentProvider);
      if (contactResource == null) {
        contactResource=new ContactResourceJabberImpl(fullJid,contact,resource,newPresenceStatus,presence.getPriority(),mobileIndicator.isMobileResource(resource,fullJid));
        resources.put(fullJid,contactResource);
        contact.fireContactResourceEvent(new ContactResourceEvent(contact,contactResource,ContactResourceEvent.RESOURCE_ADDED));
      }
 else {
        boolean oldIndicator=contactResource.isMobile();
        boolean newIndicator=mobileIndicator.isMobileResource(resource,fullJid);
        contactResource.setMobile(newIndicator);
        if (contactResource.getPresenceStatus().getStatus() != newPresenceStatus.getStatus() || (oldIndicator != newIndicator)) {
          contactResource.setPresenceStatus(newPresenceStatus);
          contact.fireContactResourceEvent(new ContactResourceEvent(contact,contactResource,ContactResourceEvent.RESOURCE_MODIFIED));
        }
      }
    }
  }
  if (!removeUnavailable)   return;
  Iterator<String> resourceIter=resources.keySet().iterator();
  while (resourceIter.hasNext()) {
    String fullJid=resourceIter.next();
    if (!parentProvider.getConnection().getRoster().getPresenceResource(fullJid).isAvailable()) {
      ContactResource removedResource=resources.get(fullJid);
      if (resources.containsKey(fullJid)) {
        resources.remove(fullJid);
        contact.fireContactResourceEvent(new ContactResourceEvent(contact,removedResource,ContactResourceEvent.RESOURCE_REMOVED));
      }
    }
  }
}