Program: 102979
Project: 102979
Buggy source:
/** 
 * When the protocol is online this method is used to fill or resolve the current contact list
 */
private void initRoster(){
  if (roster.getUnfiledEntryCount() > 0) {
    for (    RosterEntry item : roster.getUnfiledEntries()) {
      ContactJabberImpl contact=findContactById(item.getUser());
      if (!isEntryDisplayable(item)) {
        if (contact != null) {
          ContactGroup parent=contact.getParentContactGroup();
          if (parent instanceof RootContactGroupJabberImpl)           ((RootContactGroupJabberImpl)parent).removeContact(contact);
 else           ((ContactGroupJabberImpl)parent).removeContact(contact);
          fireContactRemoved(parent,contact);
        }
        continue;
      }
      if (contact == null) {
        contact=new ContactJabberImpl(item,this,true,true);
        rootGroup.addContact(contact);
        fireContactAdded(rootGroup,contact);
      }
 else {
        contact.setResolved(item);
        fireContactResolved(rootGroup,contact);
      }
      try {
        parentOperationSet.firePresenceStatusChanged(roster.getPresence(item.getUser()));
      }
 catch (      Throwable t) {
        logger.error("String_Node_Str",t);
      }
    }
  }
  Iterator<Contact> iter=rootGroup.contacts();
  List<ContactJabberImpl> contactsToRemove=new ArrayList<ContactJabberImpl>();
  while (iter.hasNext()) {
    ContactJabberImpl contact=(ContactJabberImpl)iter.next();
    if (!contact.isResolved()) {
      contactsToRemove.add(contact);
    }
  }
  for (  ContactJabberImpl contact : contactsToRemove) {
    rootGroup.removeContact(contact);
    fireContactRemoved(rootGroup,contact);
  }
  contactsToRemove.clear();
  for (  RosterGroup item : roster.getGroups()) {
    ContactGroupJabberImpl group=findContactGroup(item.getName());
    if (group == null) {
      ContactGroupJabberImpl newGroup=new ContactGroupJabberImpl(item,item.getEntries().iterator(),this,true);
      rootGroup.addSubGroup(newGroup);
      fireGroupEvent(newGroup,ServerStoredGroupEvent.GROUP_CREATED_EVENT);
      if (roster != null) {
        Iterator<Contact> cIter=newGroup.contacts();
        while (cIter.hasNext()) {
          parentOperationSet.firePresenceStatusChanged(roster.getPresence(cIter.next().getAddress()));
        }
      }
    }
 else {
      group.setResolved(item);
      fireGroupEvent(group,ServerStoredGroupEvent.GROUP_RESOLVED_EVENT);
    }
  }
  Iterator<ContactGroup> iterGroups=rootGroup.subgroups();
  List<ContactGroupJabberImpl> groupsToRemove=new ArrayList<ContactGroupJabberImpl>();
  while (iterGroups.hasNext()) {
    ContactGroupJabberImpl group=(ContactGroupJabberImpl)iterGroups.next();
    if (!group.isResolved()) {
      groupsToRemove.add(group);
    }
    Iterator<Contact> iterContacts=group.contacts();
    while (iterContacts.hasNext()) {
      ContactJabberImpl contact=(ContactJabberImpl)iterContacts.next();
      if (!contact.isResolved()) {
        contactsToRemove.add(contact);
      }
    }
    for (    ContactJabberImpl contact : contactsToRemove) {
      group.removeContact(contact);
      fireContactRemoved(group,contact);
    }
    contactsToRemove.clear();
  }
  for (  ContactGroupJabberImpl group : groupsToRemove) {
    rootGroup.removeSubGroup(group);
    fireGroupEvent(group,ServerStoredGroupEvent.GROUP_REMOVED_EVENT);
  }
}

Fixed version (ground truth):
/** 
 * When the protocol is online this method is used to fill or resolve the current contact list
 */
private void initRoster(){
  if (roster.getUnfiledEntryCount() > 0) {
    for (    RosterEntry item : roster.getUnfiledEntries()) {
      ContactJabberImpl contact=findContactById(item.getUser());
      if (!isEntryDisplayable(item)) {
        if (contact != null) {
          ContactGroup parent=contact.getParentContactGroup();
          if (parent instanceof RootContactGroupJabberImpl)           ((RootContactGroupJabberImpl)parent).removeContact(contact);
 else           ((ContactGroupJabberImpl)parent).removeContact(contact);
          fireContactRemoved(parent,contact);
        }
        continue;
      }
      if (contact == null) {
        contact=new ContactJabberImpl(item,this,true,true);
        rootGroup.addContact(contact);
        fireContactAdded(rootGroup,contact);
      }
 else {
        ContactGroup group=contact.getParentContactGroup();
        if (!rootGroup.equals(group)) {
          contactMoved(group,rootGroup,contact);
        }
        contact.setResolved(item);
        fireContactResolved(rootGroup,contact);
      }
      try {
        parentOperationSet.firePresenceStatusChanged(roster.getPresence(item.getUser()));
      }
 catch (      Throwable t) {
        logger.error("String_Node_Str",t);
      }
    }
  }
  Iterator<Contact> iter=rootGroup.contacts();
  List<ContactJabberImpl> contactsToRemove=new ArrayList<ContactJabberImpl>();
  while (iter.hasNext()) {
    ContactJabberImpl contact=(ContactJabberImpl)iter.next();
    if (!contact.isResolved()) {
      contactsToRemove.add(contact);
    }
  }
  for (  ContactJabberImpl contact : contactsToRemove) {
    rootGroup.removeContact(contact);
    fireContactRemoved(rootGroup,contact);
  }
  contactsToRemove.clear();
  for (  RosterGroup item : roster.getGroups()) {
    ContactGroupJabberImpl group=findContactGroup(item.getName());
    if (group != null) {
      group.setResolved(item);
      fireGroupEvent(group,ServerStoredGroupEvent.GROUP_RESOLVED_EVENT);
    }
  }
  Iterator<ContactGroup> iterGroups=rootGroup.subgroups();
  List<ContactGroupJabberImpl> groupsToRemove=new ArrayList<ContactGroupJabberImpl>();
  while (iterGroups.hasNext()) {
    ContactGroupJabberImpl group=(ContactGroupJabberImpl)iterGroups.next();
    if (!group.isResolved()) {
      groupsToRemove.add(group);
    }
    Iterator<Contact> iterContacts=group.contacts();
    while (iterContacts.hasNext()) {
      ContactJabberImpl contact=(ContactJabberImpl)iterContacts.next();
      if (!contact.isResolved()) {
        contactsToRemove.add(contact);
      }
    }
    for (    ContactJabberImpl contact : contactsToRemove) {
      group.removeContact(contact);
      fireContactRemoved(group,contact);
    }
    contactsToRemove.clear();
  }
  for (  ContactGroupJabberImpl group : groupsToRemove) {
    rootGroup.removeSubGroup(group);
    fireGroupEvent(group,ServerStoredGroupEvent.GROUP_REMOVED_EVENT);
  }
  for (  RosterGroup item : roster.getGroups()) {
    ContactGroupJabberImpl group=findContactGroup(item.getName());
    if (group == null) {
      ContactGroupJabberImpl newGroup=new ContactGroupJabberImpl(item,item.getEntries().iterator(),this,true);
      rootGroup.addSubGroup(newGroup);
      fireGroupEvent(newGroup,ServerStoredGroupEvent.GROUP_CREATED_EVENT);
      if (roster != null) {
        Iterator<Contact> cIter=newGroup.contacts();
        while (cIter.hasNext()) {
          String address=cIter.next().getAddress();
          parentOperationSet.firePresenceStatusChanged(roster.getPresence(address));
        }
      }
    }
  }
}