Program: 103291
Project: 103291
Buggy source:
/** 
 * Adds the entry to our local contactlist. If contact exists and is persistent but not resolved, we resolve it and return it without adding new contact. If the contact exists and is not persistent, we remove it, to avoid duplicate contacts and add the new one. All entries must be displayable before we done anything with them.
 * @param rosterEntryID the entry id.
 * @return the newly created contact.
 */
private ContactJabberImpl addEntryToContactList(String rosterEntryID){
  RosterEntry entry=roster.getEntry(rosterEntryID);
  if (!isEntryDisplayable(entry))   return null;
  ContactJabberImpl contact=findContactById(entry.getUser());
  if (contact != null) {
    if (contact.isPersistent()) {
      contact.setResolved(entry);
      return contact;
    }
 else {
      ContactGroup oldParentGroup=contact.getParentContactGroup();
      if (oldParentGroup instanceof ContactGroupJabberImpl && !oldParentGroup.isPersistent()) {
        ((ContactGroupJabberImpl)oldParentGroup).removeContact(contact);
        fireContactRemoved(oldParentGroup,contact);
      }
    }
  }
  contact=new ContactJabberImpl(entry,ServerStoredContactListJabberImpl.this,true,true);
  if (entry.getGroups() == null || entry.getGroups().size() == 0) {
    rootGroup.addContact(contact);
    fireContactAdded(rootGroup,contact);
    return contact;
  }
  for (  RosterGroup group : entry.getGroups()) {
    ContactGroupJabberImpl parentGroup=findContactGroup(group.getName());
    if (parentGroup != null) {
      parentGroup.addContact(contact);
      fireContactAdded(findContactGroup(contact),contact);
    }
 else {
      ContactGroupJabberImpl newGroup=new ContactGroupJabberImpl(group,group.getEntries().iterator(),ServerStoredContactListJabberImpl.this,true);
      rootGroup.addSubGroup(newGroup);
      fireGroupEvent(newGroup,ServerStoredGroupEvent.GROUP_CREATED_EVENT);
    }
    return contact;
  }
  return contact;
}

Fixed version (ground truth):
/** 
 * Adds the entry to our local contactlist. If contact exists and is persistent but not resolved, we resolve it and return it without adding new contact. If the contact exists and is not persistent, we remove it, to avoid duplicate contacts and add the new one. All entries must be displayable before we done anything with them.
 * @param rosterEntryID the entry id.
 * @return the newly created contact.
 */
private ContactJabberImpl addEntryToContactList(String rosterEntryID){
  RosterEntry entry=roster.getEntry(rosterEntryID);
  if (!isEntryDisplayable(entry))   return null;
  ContactJabberImpl contact=findContactById(entry.getUser());
  if (contact != null) {
    if (contact.isPersistent()) {
      contact.setResolved(entry);
      return contact;
    }
 else     if (contact instanceof VolatileContactJabberImpl) {
      ContactGroup oldParentGroup=contact.getParentContactGroup();
      if (oldParentGroup instanceof ContactGroupJabberImpl && !oldParentGroup.isPersistent()) {
        ((ContactGroupJabberImpl)oldParentGroup).removeContact(contact);
        fireContactRemoved(oldParentGroup,contact);
      }
    }
 else     return contact;
  }
  contact=new ContactJabberImpl(entry,ServerStoredContactListJabberImpl.this,true,true);
  if (entry.getGroups() == null || entry.getGroups().size() == 0) {
    rootGroup.addContact(contact);
    fireContactAdded(rootGroup,contact);
    return contact;
  }
  for (  RosterGroup group : entry.getGroups()) {
    ContactGroupJabberImpl parentGroup=findContactGroup(group.getName());
    if (parentGroup != null) {
      parentGroup.addContact(contact);
      fireContactAdded(findContactGroup(contact),contact);
    }
 else {
      ContactGroupJabberImpl newGroup=new ContactGroupJabberImpl(group,group.getEntries().iterator(),ServerStoredContactListJabberImpl.this,true);
      rootGroup.addSubGroup(newGroup);
      fireGroupEvent(newGroup,ServerStoredGroupEvent.GROUP_CREATED_EVENT);
    }
    return contact;
  }
  return contact;
}