Buggy code:
public class FilteredTree extends Composite { protected Text filterText ; protected ToolBarManager filterToolBar ; protected TreeViewer treeViewer ; protected Composite filterComposite ; private PatternFilter patternFilter ; protected String initialText = "" ; private Job refreshJob ; protected Composite parent ; protected boolean showFilterControls ; protected Composite treeComposite ; 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" ; private static final long SOFT_MAX_EXPAND_TIME = 200 ; public FilteredTree ( Composite parent , int treeStyle , PatternFilter filter ) { } protected FilteredTree ( Composite parent ) { } protected void init ( int treeStyle , PatternFilter filter ) { } protected void createControl ( Composite parent , int treeStyle ) { } protected Composite createFilterControls ( Composite parent ) { } protected Control createTreeControl ( Composite parent , int style ) { } protected TreeViewer doCreateTreeViewer ( Composite parent , int style ) { } private TreeItem getFirstMatchingItem ( TreeItem [ ] items ) { } private void createRefreshJob ( ) { refreshJob = new WorkbenchJob ( "Refresh<seq2seq4repair_space>Filter" ) { public IStatus runInUIThread ( IProgressMonitor monitor ) { if ( treeViewer . getControl ( ) . isDisposed ( ) ) { return Status . CANCEL_STATUS ; } String text = getFilterString ( ) ; if ( text == null ) { return Status . OK_STATUS ; } boolean initial = ( ( initialText ) != null ) && ( initialText . equals ( text ) ) ; if ( initial ) { patternFilter . setPattern ( null ) ; } else if ( text != null ) { patternFilter . setPattern ( text ) ; } Control redrawFalseControl = ( ( treeComposite ) != null ) ? treeComposite : treeViewer . getControl ( ) ; try { redrawFalseControl . setRedraw ( false ) ; if ( ! ( narrowingDown ) ) { TreeItem [ ] is = treeViewer . getTree ( ) . getItems ( ) ; for ( int i = 0 ; i < ( is . length ) ; i ++ ) { TreeItem item = is [ i ] ; if ( item . getExpanded ( ) ) { treeViewer . setExpandedState ( item . getData ( ) , false ) ; } } } treeViewer . refresh ( true ) ; if ( ( ( text . length ( ) ) > 0 ) && ( ! initial ) ) { TreeItem [ ] items = getViewer ( ) . getTree ( ) . getItems ( ) ; int treeHeight = getViewer ( ) . getTree ( ) . getBounds ( ) . height ; int numVisibleItems = treeHeight // ( getViewer ( ) . getTree ( ) . getItemHeight ( ) ) ; long stopTime = ( FilteredTree . SOFT_MAX_EXPAND_TIME ) + ( System . currentTimeMillis ( ) ) ; if ( ( ( items . length ) > 0 ) && ( recursiveExpand ( items , monitor , stopTime , new int [ ] { numVisibleItems } ) ) ) { return Status . CANCEL_STATUS ; } updateToolbar ( true ) ; } else { updateToolbar ( false ) ; } } finally { TreeItem [ ] items = getViewer ( ) . getTree ( ) . getItems ( ) ; <START_BUG> if ( ( items . length ) > 0 ) { <END_BUG> treeViewer . getTree ( ) . setTopItem ( items [ 0 ] ) ; } redrawFalseControl . setRedraw ( true ) ; } return Status . OK_STATUS ; } private boolean recursiveExpand ( TreeItem [ ] items , IProgressMonitor monitor , long cancelTime , int [ ] numItemsLeft ) { boolean canceled = false ; for ( int i = 0 ; ( ! canceled ) && ( i < ( items . length ) ) ; i ++ ) { TreeItem item = items [ i ] ; boolean visible = ( ( numItemsLeft [ 0 ] ) -- ) >= 0 ; if ( ( monitor . isCanceled ( ) ) || ( ( ! visible ) && ( ( System . currentTimeMillis ( ) ) > cancelTime ) ) ) { canceled = true ; } else { Object itemData = item . getData ( ) ; if ( itemData != null ) { if ( ! ( item . getExpanded ( ) ) ) { treeViewer . setExpandedState ( itemData , true ) ; } TreeItem [ ] children = item . getItems ( ) ; if ( ( items . length ) > 0 ) { canceled = recursiveExpand ( children , monitor , cancelTime , numItemsLeft ) ; } } } } return canceled ; } } ; refreshJob . setSystem ( true ) ; } protected void updateToolbar ( boolean visible ) { } protected void createFilterText ( Composite parent ) { } protected Text doCreateFilterText ( Composite parent ) { } private String previousFilterText ; private boolean narrowingDown ; protected void textChanged ( ) { } public void setBackground ( Color background ) { } private void createClearText ( Composite parent ) { } protected void clearText ( ) { } protected void setFilterText ( String string ) { } public final PatternFilter getPatternFilter ( ) { } public TreeViewer getViewer ( ) { } public Text getFilterControl ( ) { } protected String getFilterString ( ) { } public void setInitialText ( String text ) { } protected void selectAll ( ) { } protected String getInitialText ( ) { } public static Font getBoldFont ( Object element , FilteredTree tree , PatternFilter filter ) { } }

Fix:
if ( ( ( items . length ) > 0 ) && ( ( getViewer ( ) . getTree ( ) . getSelectionCount ( ) ) == 0 ) ) {