Buggy code:
public class CompleteWord extends JWindow { public static void completeWord ( View view ) { JEditTextArea textArea = view . getTextArea ( ) ; Buffer buffer = view . getBuffer ( ) ; int caretLine = textArea . getCaretLine ( ) ; int caret = textArea . getCaretPosition ( ) ; if ( ! ( buffer . isEditable ( ) ) ) { textArea . getToolkit ( ) . beep ( ) ; return ; } KeywordMap keywordMap = buffer . getKeywordMapAtOffset ( caret ) ; String noWordSep = CompleteWord . getNonAlphaNumericWordChars ( buffer , keywordMap , caret ) ; String word = CompleteWord . getWordToComplete ( buffer , caretLine , caret , noWordSep ) ; if ( word == null ) { textArea . getToolkit ( ) . beep ( ) ; return ; } Vector completions = CompleteWord . getCompletions ( buffer , word , keywordMap , noWordSep , caret ) ; if ( ( ( completions . size ( ) ) == 0 ) || ( ( ( completions . size ( ) ) == 1 ) && ( ( ( CompleteWord . Completion ) ( completions . get ( 0 ) ) ) . text . equals ( word ) ) ) ) { textArea . getToolkit ( ) . beep ( ) ; } else if ( ( completions . size ( ) ) == 1 ) { textArea . setSelectedText ( completions . elementAt ( 0 ) . toString ( ) . substring ( word . length ( ) ) ) ; } else { <START_BUG> String longestPrefix = MiscUtilities . getLongestPrefix ( completions ) ; <END_BUG> if ( ( word . length ( ) ) < ( longestPrefix . length ( ) ) ) buffer . insert ( caret , longestPrefix . substring ( word . length ( ) ) ) ; textArea . scrollToCaret ( false ) ; Point location = textArea . offsetToXY ( ( caret - ( word . length ( ) ) ) ) ; location . y += textArea . getPainter ( ) . getFontMetrics ( ) . getHeight ( ) ; SwingUtilities . convertPointToScreen ( location , textArea . getPainter ( ) ) ; new CompleteWord ( view , longestPrefix , completions , location , noWordSep ) ; } } public CompleteWord ( View view , String word , Vector completions , Point location , String noWordSep ) { } public void dispose ( ) { } private static String getNonAlphaNumericWordChars ( Buffer buffer , KeywordMap keywordMap , int caret ) { } private static String getWordToComplete ( Buffer buffer , int caretLine , int caret , String noWordSep ) { } private static Vector getCompletions ( Buffer buffer , String word , KeywordMap keywordMap , String noWordSep , int caret ) { } private static String completeWord ( String line , int offset , String noWordSep ) { } private View view ; private JEditTextArea textArea ; private Buffer buffer ; private String word ; private JList words ; private String noWordSep ; private void insertSelected ( ) { } static class Completion { String text ; boolean keyword ; Completion ( String text , boolean keyword ) { } public String toString ( ) { } public boolean equals ( Object obj ) { } } static class Renderer extends DefaultListCellRenderer { public Component getListCellRendererComponent ( JList list , Object value , int index , boolean isSelected , boolean cellHasFocus ) { } } class KeyHandler extends KeyAdapter { public void keyPressed ( KeyEvent evt ) { } public void keyTyped ( KeyEvent evt ) { } } class MouseHandler extends MouseAdapter { public void mouseClicked ( MouseEvent evt ) { } } }

Fix:
String longestPrefix = MiscUtilities . getLongestPrefix ( completions , keywordMap . getIgnoreCase ( ) ) ;