Program: 103075
Project: 103075
Buggy source:
/** 
 * Fires the status change, respecting resource priorities.
 * @param presence the presence changed.
 */
void firePresenceStatusChanged(Presence presence){
  if (storeEvents && storedPresences != null) {
    storedPresences.add(presence);
    return;
  }
  try {
    String userID=StringUtils.parseBareAddress(presence.getFrom());
    List<ChatRoom> chatRooms=parentProvider.getOperationSet(OperationSetMultiUserChat.class).getCurrentlyJoinedChatRooms();
    for (    ChatRoom chatRoom : chatRooms) {
      if (chatRoom.getName().equals(userID)) {
        userID=presence.getFrom();
        break;
      }
    }
    if (logger.isDebugEnabled())     logger.debug("String_Node_Str" + userID);
    TreeSet<Presence> userStats=statuses.get(userID);
    if (userStats == null) {
      userStats=new TreeSet<Presence>(new Comparator<Presence>(){
        public int compare(        Presence o1,        Presence o2){
          int res=o2.getPriority() - o1.getPriority();
          if (res == 0) {
            res=jabberStatusToPresenceStatus(o2,parentProvider).getStatus() - jabberStatusToPresenceStatus(o1,parentProvider).getStatus();
          }
          return res;
        }
      }
);
      statuses.put(userID,userStats);
    }
 else {
      String resource=StringUtils.parseResource(presence.getFrom());
      for (Iterator<Presence> iter=userStats.iterator(); iter.hasNext(); ) {
        Presence p=iter.next();
        if (StringUtils.parseResource(p.getFrom()).equals(resource))         iter.remove();
      }
    }
    if (!jabberStatusToPresenceStatus(presence,parentProvider).equals(parentProvider.getJabberStatusEnum().getStatus(JabberStatusEnum.OFFLINE))) {
      userStats.add(presence);
    }
    Presence currentPresence;
    if (userStats.size() == 0) {
      currentPresence=presence;
      statuses.remove(userID);
    }
 else     currentPresence=userStats.first();
    ContactJabberImpl sourceContact=ssContactList.findContactById(userID);
    if (sourceContact == null) {
      logger.warn("String_Node_Str" + userID);
      return;
    }
    sourceContact.setStatusMessage(currentPresence.getStatus());
    updateResources(sourceContact,true);
    mobileIndicator.resourcesUpdated(sourceContact);
    PresenceStatus oldStatus=sourceContact.getPresenceStatus();
    PresenceStatus newStatus=jabberStatusToPresenceStatus(currentPresence,parentProvider);
    if (oldStatus.equals(newStatus))     return;
    sourceContact.updatePresenceStatus(newStatus);
    ContactGroup parent=ssContactList.findContactGroup(sourceContact);
    if (logger.isDebugEnabled())     logger.debug("String_Node_Str");
    fireContactPresenceStatusChangeEvent(sourceContact,parent,oldStatus,newStatus);
  }
 catch (  IllegalStateException ex) {
    logger.error("String_Node_Str",ex);
  }
catch (  IllegalArgumentException ex) {
    logger.error("String_Node_Str",ex);
  }
}

Fixed version (ground truth):
/** 
 * Fires the status change, respecting resource priorities.
 * @param presence the presence changed.
 */
void firePresenceStatusChanged(Presence presence){
  if (storeEvents && storedPresences != null) {
    storedPresences.add(presence);
    return;
  }
  try {
    String userID=StringUtils.parseBareAddress(presence.getFrom());
    List<ChatRoom> chatRooms=parentProvider.getOperationSet(OperationSetMultiUserChat.class).getCurrentlyJoinedChatRooms();
    for (    ChatRoom chatRoom : chatRooms) {
      if (chatRoom.getName().equals(userID)) {
        userID=presence.getFrom();
        break;
      }
    }
    if (logger.isDebugEnabled())     logger.debug("String_Node_Str" + userID);
    TreeSet<Presence> userStats=statuses.get(userID);
    if (userStats == null) {
      userStats=new TreeSet<Presence>(new Comparator<Presence>(){
        public int compare(        Presence o1,        Presence o2){
          int res=o2.getPriority() - o1.getPriority();
          if (res == 0) {
            res=jabberStatusToPresenceStatus(o2,parentProvider).getStatus() - jabberStatusToPresenceStatus(o1,parentProvider).getStatus();
          }
          return res;
        }
      }
);
      statuses.put(userID,userStats);
    }
 else {
      String resource=StringUtils.parseResource(presence.getFrom());
      for (Iterator<Presence> iter=userStats.iterator(); iter.hasNext(); ) {
        Presence p=iter.next();
        if (StringUtils.parseResource(p.getFrom()).equals(resource))         iter.remove();
      }
    }
    if (!jabberStatusToPresenceStatus(presence,parentProvider).equals(parentProvider.getJabberStatusEnum().getStatus(JabberStatusEnum.OFFLINE))) {
      userStats.add(presence);
    }
    Presence currentPresence;
    if (userStats.size() == 0) {
      currentPresence=presence;
      statuses.remove(userID);
    }
 else     currentPresence=userStats.first();
    ContactJabberImpl sourceContact=ssContactList.findContactById(userID);
    if (sourceContact == null) {
      logger.warn("String_Node_Str" + userID);
      return;
    }
    sourceContact.setStatusMessage(currentPresence.getStatus());
    boolean oldMobileIndicator=sourceContact.isMobile();
    boolean resourceUpdated=updateResources(sourceContact,true);
    mobileIndicator.resourcesUpdated(sourceContact);
    PresenceStatus oldStatus=sourceContact.getPresenceStatus();
    PresenceStatus newStatus=jabberStatusToPresenceStatus(currentPresence,parentProvider);
    if (oldStatus.equals(newStatus) && oldMobileIndicator == sourceContact.isMobile()) {
      return;
    }
    sourceContact.updatePresenceStatus(newStatus);
    ContactGroup parent=ssContactList.findContactGroup(sourceContact);
    if (logger.isDebugEnabled())     logger.debug("String_Node_Str");
    fireContactPresenceStatusChangeEvent(sourceContact,parent,oldStatus,newStatus,resourceUpdated);
  }
 catch (  IllegalStateException ex) {
    logger.error("String_Node_Str",ex);
  }
catch (  IllegalArgumentException ex) {
    logger.error("String_Node_Str",ex);
  }
}