Program: 20504
Project: 20504
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);
        }
      }
    }
 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);
        }
      }
    }
  }
  fireRosterChangedEvent();
  rosterInitialized=true;
}

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);
        }
      }
    }
 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();
    if (rosterInitialized) {
      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));
      }
    }
    if (rosterInitialized) {
      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);
          }
        }
      }
    }
  }
  rosterInitialized=true;
  fireRosterChangedEvent();
}