Buggy code:
public class FilteredTree extends Composite { private Text filterText ; private ToolBarManager filterToolBar ; private TreeViewer treeViewer ; private Composite filterParent ; private PatternFilter patternFilter ; private ViewerFilter viewerFilter ; private FocusListener listener ; private static final String CLEAR_ICON = "org.eclipse.ui.internal.dialogs.CLEAR_ICON" ; private static final String DCLEAR_ICON = "org.eclipse.ui.internal.dialogs.DCLEAR_ICON" ; protected String initialText = "" ; private String cachedTitle ; private Job refreshJob ; public FilteredTree ( Composite parent , int treeStyle ) { } public FilteredTree ( Composite parent , int treeStyle , PatternFilter filter ) { } protected void createFilterWidgets ( Composite parent ) { filterParent = new Composite ( this , SWT . NONE ) ; GridLayout filterLayout = new GridLayout ( ) ; filterLayout . numColumns = 2 ; filterLayout . marginHeight = 0 ; filterLayout . marginWidth = 0 ; filterParent . setLayout ( filterLayout ) ; filterParent . setFont ( parent . getFont ( ) ) ; filterParent . setLayoutData ( new GridData ( SWT . FILL , SWT . BEGINNING , true , false ) ) ; createFilterText ( filterParent ) ; filterText . addKeyListener ( new KeyAdapter ( ) { public void keyPressed ( KeyEvent e ) { boolean hasItems = ( getViewer ( ) . getTree ( ) . getItemCount ( ) ) > 0 ; if ( hasItems && ( ( e . keyCode ) == ( SWT . ARROW_DOWN ) ) ) { treeViewer . getTree ( ) . setFocus ( ) ; } else if ( ( e . character ) == ( SWT . CR ) ) { return ; } else { textChanged ( ) ; } } } ) ; filterText . addTraverseListener ( new TraverseListener ( ) { public void keyTraversed ( TraverseEvent e ) { if ( ( e . detail ) == ( SWT . TRAVERSE_RETURN ) ) { e . doit = false ; if ( ( getViewer ( ) . getTree ( ) . getItemCount ( ) ) == 0 ) { Display . getCurrent ( ) . beep ( ) ; } else { boolean hasFocus = getViewer ( ) . getTree ( ) . setFocus ( ) ; boolean textChanged = ! ( getInitialText ( ) . equals ( filterText . getText ( ) . trim ( ) ) ) ; <START_BUG> if ( hasFocus && textChanged ) { <END_BUG> TreeItem item = getFirstHighlightedItem ( getViewer ( ) . getTree ( ) . getItems ( ) ) ; if ( item != null ) { getViewer ( ) . getTree ( ) . setSelection ( new TreeItem [ ] { item } ) ; ISelection sel = getViewer ( ) . getSelection ( ) ; getViewer ( ) . setSelection ( sel , true ) ; } } } } } } ) ; GridData data = new GridData ( SWT . FILL , SWT . BEGINNING , true , false ) ; filterText . setLayoutData ( data ) ; ToolBar toolBar = new ToolBar ( filterParent , ( ( SWT . FLAT ) | ( SWT . HORIZONTAL ) ) ) ; filterToolBar = new ToolBarManager ( toolBar ) ; createClearText ( filterToolBar ) ; filterToolBar . update ( false ) ; filterToolBar . getControl ( ) . setVisible ( false ) ; } private TreeItem getFirstHighlightedItem ( TreeItem [ ] items ) { } private void createRefreshJob ( ) { } protected void createFilterText ( Composite parent ) { } protected void textChanged ( ) { } public void setBackground ( Color background ) { } private void createClearText ( ToolBarManager filterToolBar ) { } protected void clearText ( ) { } protected void setFilterText ( String string ) { } public TreeViewer getViewer ( ) { } public Text getFilterControl ( ) { } protected String getFilterString ( ) { } public void setInitialText ( String text ) { } protected void selectAll ( ) { } protected String getInitialText ( ) { } public void addFilter ( ViewerFilter filter ) { } protected static Font getBoldFont ( Object element , FilteredTree tree , PatternFilter filter ) { } }

Fix:
if ( ( hasFocus && textChanged ) && ( ( filterText . getText ( ) . trim ( ) . length ( ) ) > 0 ) ) {