Program: 103313
Project: 103313
Buggy source:
/** 
 * Fires the status change, respecting resource priorities.
 * @param presence the presence changed.
 */
void firePresenceStatusChanged(Presence presence){
  try {
    String userID=StringUtils.parseBareAddress(presence.getFrom());
    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=o1.getPriority() - o2.getPriority();
          if (res == 0) {
            res=jabberStatusToPresenceStatus(o1,parentProvider).getStatus() - jabberStatusToPresenceStatus(o2,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());
    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){
  try {
    String userID=StringUtils.parseBareAddress(presence.getFrom());
    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());
    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);
  }
}