Program: 104111
Project: 104111
Buggy source:
/** 
 * Searches the contact list when any key, different from "space", "+" or "-" is typed. Selects the Contact name closest to the typed string. The time between two button presses is checked to determine whether the user makes a new search or a continuous search. When user types the same letter consecutively the search mechanism selects the next Contact name starting with the same letter.
 */
public void keyTyped(KeyEvent e){
  if (contactList.getModel().getSize() <= 0)   return;
  long eventTimestamp=e.getWhen();
  char keyChar=e.getKeyChar();
  if (keyChar == ' ') {
    closeGroup();
  }
 else   if (keyChar == '+') {
    openGroup();
  }
 else   if (keyChar == '-') {
    closeGroup();
  }
 else {
    if ((lastTypedTimestamp - eventTimestamp) > 1000) {
      keyBuffer.delete(0,keyBuffer.length() - 1);
    }
    this.lastTypedTimestamp=eventTimestamp;
    this.keyBuffer.append(keyChar);
    boolean selectedSameLetterContact=false;
    int selectedIndex=this.contactList.getSelectedIndex();
    if (selectedIndex != -1) {
      Object selectedObject=this.contactList.getSelectedValue();
      if (selectedObject instanceof MetaContact) {
        String selectedContactName=((MetaContact)selectedObject).getDisplayName();
        if (selectedContactName != null) {
          selectedSameLetterContact=selectedContactName.substring(0,1).equalsIgnoreCase(keyBuffer.toString());
        }
      }
    }
    int contactIndex=contactList.getNextMatch(keyBuffer.toString(),(lastTypedKey != keyChar || !selectedSameLetterContact) ? 0 : selectedIndex + 1,Position.Bias.Forward);
    int currentlySelectedIndex=this.contactList.getSelectedIndex();
    if (currentlySelectedIndex != contactIndex && contactIndex != -1) {
      this.contactList.setSelectedIndex(contactIndex);
      currentlySelectedIndex=contactList.getSelectedIndex();
    }
    this.contactList.ensureIndexIsVisible(currentlySelectedIndex);
    this.lastTypedKey=keyChar;
  }
}

Fixed version (ground truth):
/** 
 * Searches the contact list when any key, different from "space", "+" or "-" is typed. Selects the Contact name closest to the typed string. The time between two button presses is checked to determine whether the user makes a new search or a continuous search. When user types the same letter consecutively the search mechanism selects the next Contact name starting with the same letter.
 */
public void keyTyped(KeyEvent e){
  if (contactList.getModel().getSize() <= 0)   return;
  long eventTimestamp=e.getWhen();
  char keyChar=e.getKeyChar();
  if (keyChar == ' ') {
    openOrCloseGroup();
  }
 else   if (keyChar == '+') {
    openGroup();
  }
 else   if (keyChar == '-') {
    closeGroup();
  }
 else {
    if ((lastTypedTimestamp - eventTimestamp) > 1000) {
      keyBuffer.delete(0,keyBuffer.length() - 1);
    }
    this.lastTypedTimestamp=eventTimestamp;
    this.keyBuffer.append(keyChar);
    boolean selectedSameLetterContact=false;
    int selectedIndex=this.contactList.getSelectedIndex();
    if (selectedIndex != -1) {
      Object selectedObject=this.contactList.getSelectedValue();
      if (selectedObject instanceof MetaContact) {
        String selectedContactName=((MetaContact)selectedObject).getDisplayName();
        if (selectedContactName != null) {
          selectedSameLetterContact=selectedContactName.substring(0,1).equalsIgnoreCase(keyBuffer.toString());
        }
      }
    }
    int contactIndex=contactList.getNextMatch(keyBuffer.toString(),(lastTypedKey != keyChar || !selectedSameLetterContact) ? 0 : selectedIndex + 1,Position.Bias.Forward);
    int currentlySelectedIndex=this.contactList.getSelectedIndex();
    if (currentlySelectedIndex != contactIndex && contactIndex != -1) {
      this.contactList.setSelectedIndex(contactIndex);
      currentlySelectedIndex=contactList.getSelectedIndex();
    }
    this.contactList.ensureIndexIsVisible(currentlySelectedIndex);
    this.lastTypedKey=keyChar;
  }
}