Program: 104570
Project: 104570
Buggy source:
/** 
 * Called by joust sim to notify us that a new buddy has been added to the contact list.
 * @param list the <tt>BuddyList</tt> owning the newly added buddy.
 * @param joustSimGroup the parent group of the added buddy.
 * @param oldItems unused
 * @param newItems unused
 * @param buddy the newly added <tt>buddy</tt>
 */
public void buddyAdded(BuddyList list,Group joustSimGroup,List oldItems,List newItems,Buddy buddy){
  ContactGroupIcqImpl oldParentGroup=null;
  ContactIcqImpl newContact=findContactByScreenName(buddy.getScreenname().getFormatted());
  if (newContact == null) {
    newContact=new ContactIcqImpl(buddy,ServerStoredContactListIcqImpl.this,true);
  }
 else {
    oldParentGroup=findContactGroup(newContact);
    newContact.setJoustSimBuddy(buddy);
    newContact.setPersistent(true);
  }
  ContactGroupIcqImpl parentGroup=findContactGroup(joustSimGroup);
  if (parentGroup == null) {
    logger.debug("String_Node_Str" + joustSimGroup + "String_Node_Str"+ buddy);
    return;
  }
  int buddyIndex=newItems.indexOf(buddy);
  if (buddyIndex == -1) {
    logger.debug(buddy + "String_Node_Str" + newItems);
  }
  int insertPos=0;
  if (buddyIndex == 0) {
    parentGroup.addContact(insertPos,newContact);
  }
 else {
    for (; buddyIndex >= 0; buddyIndex--) {
      int prevContactIndex=parentGroup.findContactIndex((Buddy)newItems.get(buddyIndex));
      if (prevContactIndex != -1)       insertPos=prevContactIndex + 1;
    }
    parentGroup.addContact(insertPos,newContact);
  }
  buddy.addBuddyListener(jsimBuddyListener);
  if (oldParentGroup == null) {
    fireContactAdded(parentGroup,newContact,insertPos);
  }
 else {
    fireContactMoved(oldParentGroup,parentGroup,newContact,insertPos);
  }
}

Fixed version (ground truth):
/** 
 * Called by joust sim to notify us that a new buddy has been added to the contact list.
 * @param list the <tt>BuddyList</tt> owning the newly added buddy.
 * @param joustSimGroup the parent group of the added buddy.
 * @param oldItems unused
 * @param newItems unused
 * @param buddy the newly added <tt>buddy</tt>
 */
public void buddyAdded(BuddyList list,Group joustSimGroup,List oldItems,List newItems,Buddy buddy){
  ContactGroupIcqImpl oldParentGroup=null;
  ContactIcqImpl newContact=findContactByScreenName(buddy.getScreenname().getFormatted());
  if (newContact == null) {
    newContact=new ContactIcqImpl(buddy,ServerStoredContactListIcqImpl.this,true);
  }
 else {
    oldParentGroup=findContactGroup(newContact);
    oldParentGroup.removeContact(newContact);
    newContact.setJoustSimBuddy(buddy);
    newContact.setPersistent(true);
  }
  ContactGroupIcqImpl parentGroup=findContactGroup(joustSimGroup);
  if (parentGroup == null) {
    logger.debug("String_Node_Str" + joustSimGroup + "String_Node_Str"+ buddy);
    return;
  }
  int buddyIndex=newItems.indexOf(buddy);
  if (buddyIndex == -1) {
    logger.debug(buddy + "String_Node_Str" + newItems);
  }
  int insertPos=0;
  if (buddyIndex == 0) {
    parentGroup.addContact(insertPos,newContact);
  }
 else {
    for (; buddyIndex >= 0; buddyIndex--) {
      int prevContactIndex=parentGroup.findContactIndex((Buddy)newItems.get(buddyIndex));
      if (prevContactIndex != -1)       insertPos=prevContactIndex + 1;
    }
    parentGroup.addContact(insertPos,newContact);
  }
  buddy.addBuddyListener(jsimBuddyListener);
  if (oldParentGroup == null) {
    fireContactAdded(parentGroup,newContact,insertPos);
  }
 else {
    fireContactMoved(oldParentGroup,parentGroup,newContact,insertPos);
  }
}