Program: 150493
Project: 150493
Buggy source:
private void showCompletion(){
  try {
    int caretPosition=editorTextArea.getCaretPosition();
    int wordStart=getWordStart();
    CompletionCandidate[] words=getFilteredWords(wordStart,editorTextArea.getText(wordStart,caretPosition - wordStart));
    if (words.length == 0) {
      return;
    }
    final JPopupMenu w=new JPopupMenu();
    final JList jList=new JList(words);
    jList.setCellRenderer(new DefaultListCellRenderer(){
      private ImageIcon tableIcon=new ImageIcon(getClass().getResource("String_Node_Str"));
      private ImageIcon tableColumnIcon=new ImageIcon(getClass().getResource("String_Node_Str"));
      private ImageIcon sqlIcon=new ImageIcon(getClass().getResource("String_Node_Str"));
      @Override public Component getListCellRendererComponent(      JList list,      Object value,      int index,      boolean isSelected,      boolean cellHasFocus){
        Component c=super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
        if (c instanceof JLabel) {
          Icon icon;
switch (((CompletionCandidate)value).getKeyWordType()) {
case TABLE:
            icon=tableIcon;
          break;
case TABLE_COlUMN:
        icon=tableColumnIcon;
      break;
default :
    icon=sqlIcon;
  break;
}
((JLabel)c).setIcon(icon);
}
return c;
}
}
);
jList.setSelectedIndex(0);
jList.addKeyListener(new KeyAdapter(){
@Override public void keyPressed(KeyEvent e){
switch (e.getKeyCode()) {
case KeyEvent.VK_PAGE_UP:
case KeyEvent.VK_PAGE_DOWN:
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_HOME:
case KeyEvent.VK_END:
case KeyEvent.VK_ESCAPE:
return;
case KeyEvent.VK_ENTER:
editorTextArea.replaceRange(((CompletionCandidate)jList.getSelectedValue()).toString(),getWordStart(),editorTextArea.getCaretPosition());
w.setVisible(false);
return;
}
editorTextArea.dispatchEvent(new KeyEvent(editorTextArea,e.getID(),e.getWhen(),e.getModifiers(),e.getKeyCode(),e.getKeyChar(),e.getKeyLocation()));
if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
adjustListContent();
}
}
@Override public void keyReleased(KeyEvent e){
switch (e.getKeyCode()) {
case KeyEvent.VK_PAGE_UP:
case KeyEvent.VK_PAGE_DOWN:
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_HOME:
case KeyEvent.VK_END:
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_ENTER:
return;
}
editorTextArea.dispatchEvent(new KeyEvent(editorTextArea,e.getID(),e.getWhen(),e.getModifiers(),e.getKeyCode(),e.getKeyChar(),e.getKeyLocation()));
if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
adjustListContent();
}
}
@Override public void keyTyped(KeyEvent e){
switch (e.getKeyCode()) {
case KeyEvent.VK_PAGE_UP:
case KeyEvent.VK_PAGE_DOWN:
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_HOME:
case KeyEvent.VK_END:
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_ENTER:
return;
}
editorTextArea.dispatchEvent(new KeyEvent(editorTextArea,e.getID(),e.getWhen(),e.getModifiers(),e.getKeyCode(),e.getKeyChar(),e.getKeyLocation()));
if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
adjustListContent();
}
}
private void adjustListContent(){
try {
int wordStart=getWordStart();
CompletionCandidate[] words=getFilteredWords(wordStart,editorTextArea.getText(wordStart,editorTextArea.getCaretPosition() - wordStart));
if (words.length == 0) {
w.setVisible(false);
return;
}
jList.setListData(words);
jList.setSelectedIndex(0);
}
 catch (BadLocationException e) {
e.printStackTrace();
}
}
}
);
jList.addMouseListener(new MouseAdapter(){
@Override public void mousePressed(MouseEvent e){
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
editorTextArea.replaceRange(((CompletionCandidate)jList.getSelectedValue()).toString(),getWordStart(),editorTextArea.getCaretPosition());
w.setVisible(false);
}
}
}
);
w.add(new JScrollPane(jList),BorderLayout.CENTER);
w.setPreferredSize(new Dimension(200,200));
Rectangle position=editorTextArea.modelToView(caretPosition);
w.show(editorTextArea,position.x + position.width,position.y + position.height);
jList.requestFocus();
}
 catch (BadLocationException e) {
e.printStackTrace();
}
}

Fixed version (ground truth):
private void showCompletion(){
  try {
    int caretPosition=editorTextArea.getCaretPosition();
    int wordStart=getWordStart();
    CompletionCandidate[] words=getFilteredWords(wordStart,editorTextArea.getText(wordStart,caretPosition - wordStart));
    if (words.length == 0) {
      return;
    }
    final JPopupMenu w=new JPopupMenu();
    final JList jList=new JList(words);
    jList.setCellRenderer(new DefaultListCellRenderer(){
      private ImageIcon tableIcon=new ImageIcon(getClass().getResource("String_Node_Str"));
      private ImageIcon tableColumnIcon=new ImageIcon(getClass().getResource("String_Node_Str"));
      private ImageIcon sqlIcon=new ImageIcon(getClass().getResource("String_Node_Str"));
      @Override public Component getListCellRendererComponent(      JList list,      Object value,      int index,      boolean isSelected,      boolean cellHasFocus){
        Component c=super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
        if (c instanceof JLabel) {
          Icon icon;
switch (((CompletionCandidate)value).getKeyWordType()) {
case TABLE:
            icon=tableIcon;
          break;
case TABLE_COlUMN:
        icon=tableColumnIcon;
      break;
default :
    icon=sqlIcon;
  break;
}
((JLabel)c).setIcon(icon);
}
return c;
}
}
);
jList.setSelectedIndex(0);
jList.addKeyListener(new KeyAdapter(){
@Override public void keyPressed(KeyEvent e){
switch (e.getKeyCode()) {
case KeyEvent.VK_PAGE_UP:
case KeyEvent.VK_PAGE_DOWN:
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_HOME:
case KeyEvent.VK_END:
return;
case KeyEvent.VK_ESCAPE:
w.setVisible(false);
return;
case KeyEvent.VK_ENTER:
editorTextArea.replaceRange(((CompletionCandidate)jList.getSelectedValue()).toString(),getWordStart(),editorTextArea.getCaretPosition());
w.setVisible(false);
return;
}
editorTextArea.dispatchEvent(new KeyEvent(editorTextArea,e.getID(),e.getWhen(),e.getModifiers(),e.getKeyCode(),e.getKeyChar(),e.getKeyLocation()));
if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
adjustListContent();
}
}
@Override public void keyReleased(KeyEvent e){
switch (e.getKeyCode()) {
case KeyEvent.VK_PAGE_UP:
case KeyEvent.VK_PAGE_DOWN:
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_HOME:
case KeyEvent.VK_END:
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_ENTER:
return;
}
editorTextArea.dispatchEvent(new KeyEvent(editorTextArea,e.getID(),e.getWhen(),e.getModifiers(),e.getKeyCode(),e.getKeyChar(),e.getKeyLocation()));
if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
adjustListContent();
}
}
@Override public void keyTyped(KeyEvent e){
switch (e.getKeyCode()) {
case KeyEvent.VK_PAGE_UP:
case KeyEvent.VK_PAGE_DOWN:
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
case KeyEvent.VK_HOME:
case KeyEvent.VK_END:
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_ENTER:
return;
}
editorTextArea.dispatchEvent(new KeyEvent(editorTextArea,e.getID(),e.getWhen(),e.getModifiers(),e.getKeyCode(),e.getKeyChar(),e.getKeyLocation()));
if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
adjustListContent();
}
}
private void adjustListContent(){
try {
int wordStart=getWordStart();
CompletionCandidate[] words=getFilteredWords(wordStart,editorTextArea.getText(wordStart,editorTextArea.getCaretPosition() - wordStart));
if (words.length == 0) {
w.setVisible(false);
return;
}
jList.setListData(words);
jList.setSelectedIndex(0);
}
 catch (BadLocationException e) {
e.printStackTrace();
}
}
}
);
jList.addMouseListener(new MouseAdapter(){
@Override public void mousePressed(MouseEvent e){
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
editorTextArea.replaceRange(((CompletionCandidate)jList.getSelectedValue()).toString(),getWordStart(),editorTextArea.getCaretPosition());
w.setVisible(false);
}
}
}
);
w.add(new JScrollPane(jList),BorderLayout.CENTER);
w.setPreferredSize(new Dimension(200,200));
Rectangle position=editorTextArea.modelToView(caretPosition);
w.show(editorTextArea,position.x + position.width,position.y + position.height);
jList.requestFocus();
}
 catch (BadLocationException e) {
e.printStackTrace();
}
}