Program: 20485
Project: 20485
Buggy source:
public void processPacket(Packet packet){
  RosterPacket rosterPacket=(RosterPacket)packet;
  for (Iterator i=rosterPacket.getRosterItems(); i.hasNext(); ) {
    RosterPacket.Item item=(RosterPacket.Item)i.next();
    RosterEntry entry=new RosterEntry(item.getUser(),item.getName(),item.getItemType(),connection);
    if (RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
      if (entries.contains(entry)) {
        entries.remove(entry);
      }
synchronized (unfiledEntries) {
        if (unfiledEntries.contains(entry)) {
          unfiledEntries.remove(entry);
        }
      }
      String key=StringUtils.parseName(item.getUser()) + "String_Node_Str" + StringUtils.parseServer(item.getUser());
      presenceMap.remove(key);
    }
 else {
      if (!entries.contains(entry)) {
        entries.add(entry);
      }
 else {
        RosterEntry existingEntry=(RosterEntry)entries.get(entries.indexOf(entry));
        existingEntry.updateState(entry.getName(),entry.getType());
      }
      if (item.getGroupNames().hasNext()) {
synchronized (unfiledEntries) {
          unfiledEntries.remove(entry);
        }
      }
 else {
synchronized (unfiledEntries) {
          if (!unfiledEntries.contains(entry)) {
            unfiledEntries.add(entry);
          }
        }
      }
    }
    List currentGroupNames=new ArrayList();
    for (Iterator j=entry.getGroups(); j.hasNext(); ) {
      RosterGroup group=(RosterGroup)j.next();
      currentGroupNames.add(group.getName());
    }
    if (!RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
      List newGroupNames=new ArrayList();
      for (Iterator k=item.getGroupNames(); k.hasNext(); ) {
        String groupName=(String)k.next();
        newGroupNames.add(groupName);
        RosterGroup group=getGroup(groupName);
        if (group == null) {
          group=createGroup(groupName);
          groups.put(groupName,group);
        }
        group.addEntryLocal(entry);
      }
      for (int m=0; m < newGroupNames.size(); m++) {
        currentGroupNames.remove(newGroupNames.get(m));
      }
    }
    for (int n=0; n < currentGroupNames.size(); n++) {
      String groupName=(String)currentGroupNames.get(n);
      RosterGroup group=getGroup(groupName);
      group.removeEntryLocal(entry);
      if (group.getEntryCount() == 0) {
synchronized (groups) {
          groups.remove(groupName);
        }
      }
    }
    for (Iterator it=getGroups(); it.hasNext(); ) {
      RosterGroup group=(RosterGroup)it.next();
      if (group.getEntryCount() == 0) {
synchronized (groups) {
          groups.remove(group.getName());
        }
      }
    }
  }
synchronized (this) {
    rosterInitialized=true;
    notifyAll();
  }
  fireRosterChangedEvent();
}

Fixed version (ground truth):
public void processPacket(Packet packet){
  RosterPacket rosterPacket=(RosterPacket)packet;
  for (Iterator i=rosterPacket.getRosterItems(); i.hasNext(); ) {
    RosterPacket.Item item=(RosterPacket.Item)i.next();
    RosterEntry entry=new RosterEntry(item.getUser(),item.getName(),item.getItemType(),connection);
    if (RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
      if (entries.contains(entry)) {
        entries.remove(entry);
      }
synchronized (unfiledEntries) {
        if (unfiledEntries.contains(entry)) {
          unfiledEntries.remove(entry);
        }
      }
      String key=StringUtils.parseName(item.getUser()) + "String_Node_Str" + StringUtils.parseServer(item.getUser());
      presenceMap.remove(key);
    }
 else {
      if (!entries.contains(entry)) {
        entries.add(entry);
      }
 else {
        RosterEntry existingEntry=(RosterEntry)entries.get(entries.indexOf(entry));
        existingEntry.updateState(entry.getName(),entry.getType());
      }
      if (item.getGroupNames().hasNext()) {
synchronized (unfiledEntries) {
          unfiledEntries.remove(entry);
        }
      }
 else {
synchronized (unfiledEntries) {
          if (!unfiledEntries.contains(entry)) {
            unfiledEntries.add(entry);
          }
        }
      }
    }
    List currentGroupNames=new ArrayList();
    for (Iterator j=entry.getGroups(); j.hasNext(); ) {
      RosterGroup group=(RosterGroup)j.next();
      currentGroupNames.add(group.getName());
    }
    if (!RosterPacket.ItemType.REMOVE.equals(item.getItemType())) {
      List newGroupNames=new ArrayList();
      for (Iterator k=item.getGroupNames(); k.hasNext(); ) {
        String groupName=(String)k.next();
        newGroupNames.add(groupName);
        RosterGroup group=getGroup(groupName);
        if (group == null) {
          group=createGroup(groupName);
          groups.put(groupName,group);
        }
        group.addEntryLocal(entry);
      }
      for (int m=0; m < newGroupNames.size(); m++) {
        currentGroupNames.remove(newGroupNames.get(m));
      }
    }
    for (int n=0; n < currentGroupNames.size(); n++) {
      String groupName=(String)currentGroupNames.get(n);
      RosterGroup group=getGroup(groupName);
      group.removeEntryLocal(entry);
      if (group.getEntryCount() == 0) {
synchronized (groups) {
          groups.remove(groupName);
        }
      }
    }
    for (Iterator it=getGroups(); it.hasNext(); ) {
      RosterGroup group=(RosterGroup)it.next();
      if (group.getEntryCount() == 0) {
synchronized (groups) {
          groups.remove(group.getName());
        }
      }
    }
  }
synchronized (Roster.this) {
    rosterInitialized=true;
    Roster.this.notifyAll();
  }
  fireRosterChangedEvent();
}