Program: 157842
Project: 157842
Buggy source:
public void showDialog(Choice choice,UUID objectId,MageDialogState mageDialogState,String startSelectionValue){
  this.choice=choice;
  setLabelText(this.labelMessage,choice.getMessage());
  setLabelText(this.labelSubMessage,choice.getSubMessage());
  btCancel.setEnabled(!choice.isRequired());
  this.allItems.clear();
  if (choice.isKeyChoice()) {
    for (    Map.Entry<String,String> entry : choice.getKeyChoices().entrySet()) {
      this.allItems.add(new KeyValueItem(entry.getKey(),entry.getValue()));
    }
  }
 else {
    for (    String value : choice.getChoices()) {
      this.allItems.add(new KeyValueItem(value,value));
    }
  }
  if (choice.isSortEnabled()) {
    Collections.sort(this.allItems,new Comparator<KeyValueItem>(){
      @Override public int compare(      KeyValueItem o1,      KeyValueItem o2){
        Integer n1=choice.getSortData().get(o1.Key);
        Integer n2=choice.getSortData().get(o2.Key);
        return n1.compareTo(n2);
      }
    }
);
  }
  if (choice.isSearchEnabled()) {
    panelSearch.setVisible(true);
    this.editSearch.setText(choice.getSearchText());
  }
 else {
    panelSearch.setVisible(false);
    this.editSearch.setText("String_Node_Str");
  }
  editSearch.getDocument().addDocumentListener(new DocumentListener(){
    @Override public void insertUpdate(    DocumentEvent e){
      choice.setSearchText(editSearch.getText());
      loadData();
    }
    @Override public void removeUpdate(    DocumentEvent e){
      choice.setSearchText(editSearch.getText());
      loadData();
    }
    @Override public void changedUpdate(    DocumentEvent e){
      choice.setSearchText(editSearch.getText());
      loadData();
    }
  }
);
  editSearch.addKeyListener(new KeyListener(){
    @Override public void keyTyped(    KeyEvent e){
    }
    @Override public void keyPressed(    KeyEvent e){
      if (e.getKeyCode() == KeyEvent.VK_UP) {
        doPrevSelect();
      }
 else       if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        doNextSelect();
      }
    }
    @Override public void keyReleased(    KeyEvent e){
    }
  }
);
  listChoices.addMouseListener(new MouseAdapter(){
    @Override public void mouseClicked(    MouseEvent e){
      if (e.getClickCount() == 2) {
        doChoose();
      }
    }
  }
);
  if (!choice.isRequired()) {
    String cancelName="String_Node_Str";
    InputMap inputMap=getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0),cancelName);
    ActionMap actionMap=getRootPane().getActionMap();
    actionMap.put(cancelName,new AbstractAction(){
      public void actionPerformed(      ActionEvent e){
        doCancel();
      }
    }
);
  }
  MageFrame.getDesktop().add(this,JLayeredPane.PALETTE_LAYER);
  if (mageDialogState != null) {
    mageDialogState.setStateToDialog(this);
  }
 else {
    Point centered=SettingsManager.instance.getComponentPosition(getWidth(),getHeight());
    this.setLocation(centered.x,centered.y);
    GuiDisplayUtil.keepComponentInsideScreen(centered.x,centered.y,this);
  }
  loadData();
  if ((startSelectionValue != null)) {
    int selectIndex=-1;
    for (int i=0; i < this.listChoices.getModel().getSize(); i++) {
      KeyValueItem listItem=(KeyValueItem)this.listChoices.getModel().getElementAt(i);
      if (listItem.Key.equals(startSelectionValue)) {
        selectIndex=i;
        break;
      }
    }
    if (selectIndex >= 0) {
      this.listChoices.setSelectedIndex(selectIndex);
      this.listChoices.ensureIndexIsVisible(selectIndex);
    }
  }
  this.setVisible(true);
}

Fixed version (ground truth):
public void showDialog(Choice choice,UUID objectId,MageDialogState mageDialogState,String startSelectionValue){
  this.choice=choice;
  setLabelText(this.labelMessage,choice.getMessage());
  setLabelText(this.labelSubMessage,choice.getSubMessage());
  btCancel.setEnabled(!choice.isRequired());
  this.allItems.clear();
  if (choice.isKeyChoice()) {
    for (    Map.Entry<String,String> entry : choice.getKeyChoices().entrySet()) {
      this.allItems.add(new KeyValueItem(entry.getKey(),entry.getValue()));
    }
  }
 else {
    for (    String value : choice.getChoices()) {
      this.allItems.add(new KeyValueItem(value,value));
    }
  }
  if (choice.isSortEnabled()) {
    Collections.sort(this.allItems,new Comparator<KeyValueItem>(){
      @Override public int compare(      KeyValueItem o1,      KeyValueItem o2){
        Integer n1=choice.getSortData().get(o1.Key);
        Integer n2=choice.getSortData().get(o2.Key);
        return n1.compareTo(n2);
      }
    }
);
  }
  if (choice.isSearchEnabled()) {
    panelSearch.setVisible(true);
    this.editSearch.setText(choice.getSearchText());
  }
 else {
    panelSearch.setVisible(false);
    this.editSearch.setText("String_Node_Str");
  }
  editSearch.getDocument().addDocumentListener(new DocumentListener(){
    @Override public void insertUpdate(    DocumentEvent e){
      choice.setSearchText(editSearch.getText());
      loadData();
    }
    @Override public void removeUpdate(    DocumentEvent e){
      choice.setSearchText(editSearch.getText());
      loadData();
    }
    @Override public void changedUpdate(    DocumentEvent e){
      choice.setSearchText(editSearch.getText());
      loadData();
    }
  }
);
  editSearch.addKeyListener(new KeyListener(){
    @Override public void keyTyped(    KeyEvent e){
    }
    @Override public void keyPressed(    KeyEvent e){
      if (e.getKeyCode() == KeyEvent.VK_UP) {
        doPrevSelect();
      }
 else       if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        doNextSelect();
      }
    }
    @Override public void keyReleased(    KeyEvent e){
    }
  }
);
  listChoices.addMouseListener(new MouseAdapter(){
    @Override public void mouseClicked(    MouseEvent e){
      if (e.getClickCount() == 2) {
        doChoose();
      }
    }
  }
);
  if (!choice.isRequired()) {
    String cancelName="String_Node_Str";
    InputMap inputMap=getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0),cancelName);
    ActionMap actionMap=getRootPane().getActionMap();
    actionMap.put(cancelName,new AbstractAction(){
      public void actionPerformed(      ActionEvent e){
        doCancel();
      }
    }
);
  }
  if (this.isModal()) {
    MageFrame.getDesktop().add(this,JLayeredPane.MODAL_LAYER);
  }
 else {
    MageFrame.getDesktop().add(this,JLayeredPane.PALETTE_LAYER);
  }
  if (mageDialogState != null) {
    mageDialogState.setStateToDialog(this);
  }
 else {
    Point centered=SettingsManager.instance.getComponentPosition(getWidth(),getHeight());
    this.setLocation(centered.x,centered.y);
    GuiDisplayUtil.keepComponentInsideScreen(centered.x,centered.y,this);
  }
  loadData();
  if ((startSelectionValue != null)) {
    int selectIndex=-1;
    for (int i=0; i < this.listChoices.getModel().getSize(); i++) {
      KeyValueItem listItem=(KeyValueItem)this.listChoices.getModel().getElementAt(i);
      if (listItem.Key.equals(startSelectionValue)) {
        selectIndex=i;
        break;
      }
    }
    if (selectIndex >= 0) {
      this.listChoices.setSelectedIndex(selectIndex);
      this.listChoices.ensureIndexIsVisible(selectIndex);
    }
  }
  this.setVisible(true);
}