Buggy code:
void createHeaderToolTips ( ) { } void createItem ( TreeColumn column , int index ) { } void createItem ( TreeItem item , int hParent , int hInsertAfter , int hItem ) { } void createItemToolTips ( ) { } void createParent ( ) { } void createWidget ( ) { } int defaultBackground ( ) { } void deregister ( ) { } void deselect ( int hItem , TVITEM tvItem , int hIgnoreItem ) { } public void deselect ( TreeItem item ) { } public void deselectAll ( ) { } void destroyItem ( TreeColumn column ) { } void destroyItem ( TreeItem item , int hItem ) { } void destroyScrollBar ( int type ) { } void enableDrag ( boolean enabled ) { } void enableWidget ( boolean enabled ) { } boolean findCell ( int x , int y , TreeItem [ ] item , int [ ] index , RECT [ ] cellRect , RECT [ ] itemRect ) { } int findIndex ( int hFirstItem , int hItem ) { } Widget findItem ( int hItem ) { } int findItem ( int hFirstItem , int index ) { } TreeItem getFocusItem ( ) { } public int getGridLineWidth ( ) { } public int getHeaderHeight ( ) { } public boolean getHeaderVisible ( ) { } Point getImageSize ( ) { } int getBottomItem ( ) { } public TreeColumn getColumn ( int index ) { } public int getColumnCount ( ) { } public int [ ] getColumnOrder ( ) { } public TreeColumn [ ] getColumns ( ) { } public TreeItem getItem ( int index ) { } TreeItem getItem ( NMTVCUSTOMDRAW nmcd ) { } public TreeItem getItem ( Point point ) { } public int getItemCount ( ) { } int getItemCount ( int hItem ) { } public int getItemHeight ( ) { } public TreeItem [ ] getItems ( ) { } TreeItem [ ] getItems ( int hTreeItem ) { } public boolean getLinesVisible ( ) { } int getNextSelection ( int hItem , TVITEM tvItem ) { } public TreeItem getParentItem ( ) { } int getSelection ( int hItem , TVITEM tvItem , TreeItem [ ] selection , int index , int count , boolean bigSelection , boolean all ) { } public TreeItem [ ] getSelection ( ) { } public int getSelectionCount ( ) { } public TreeColumn getSortColumn ( ) { } int getSortColumnPixel ( ) { } public int getSortDirection ( ) { } public TreeItem getTopItem ( ) { } boolean hitTestSelection ( int hItem , int x , int y ) { } int imageIndex ( Image image , int index ) { } int imageIndexHeader ( Image image ) { } public int indexOf ( TreeColumn column ) { } public int indexOf ( TreeItem item ) { } boolean isCustomToolTip ( ) { } boolean isItemSelected ( NMTVCUSTOMDRAW nmcd ) { } void redrawSelection ( ) { if ( ( ( style ) & ( SWT . SINGLE ) ) != 0 ) { int hItem = OS . SendMessage ( handle , TVM_GETNEXTITEM , TVGN_CARET , 0 ) ; if ( hItem != 0 ) { RECT rect = new RECT ( ) ; if ( OS . TreeView_GetItemRect ( handle , hItem , rect , false ) ) { OS . InvalidateRect ( handle , rect , true ) ; } } } else { int hItem = OS . SendMessage ( handle , TVM_GETNEXTITEM , TVGN_FIRSTVISIBLE , 0 ) ; if ( hItem != 0 ) { TVITEM tvItem = null ; if ( OS . IsWinCE ) { tvItem = new TVITEM ( ) ; tvItem . mask = OS . TVIF_STATE ; } RECT rect = new RECT ( ) ; int index = 0 ; int count = ( ( int ) ( OS . SendMessage ( handle , TVM_GETVISIBLECOUNT , 0 , 0 ) ) ) ; <START_BUG> while ( ( index < count ) && ( hItem != 0 ) ) { <END_BUG> int state = 0 ; if ( OS . IsWinCE ) { tvItem . hItem = hItem ; OS . SendMessage ( handle , TVM_GETITEM , 0 , tvItem ) ; state = tvItem . state ; } else { state = ( ( int ) ( OS . SendMessage ( handle , TVM_GETITEMSTATE , hItem , TVIS_SELECTED ) ) ) ; } if ( ( state & ( OS . TVIS_SELECTED ) ) != 0 ) { if ( OS . TreeView_GetItemRect ( handle , hItem , rect , false ) ) { OS . InvalidateRect ( handle , rect , true ) ; } } hItem = OS . SendMessage ( handle , TVM_GETNEXTITEM , TVGN_NEXTVISIBLE , hItem ) ; index ++ ; } } } } void register ( ) { } void releaseItem ( int hItem , TVITEM tvItem , boolean release ) { } void releaseItems ( int hItem , TVITEM tvItem ) { } void releaseHandle ( ) { } void releaseChildren ( boolean destroy ) { } void releaseWidget ( ) { } public void removeAll ( ) { } public void removeSelectionListener ( SelectionListener listener ) { } public void removeTreeListener ( TreeListener listener ) { } public void setInsertMark ( TreeItem item , boolean before ) { } public void setItemCount ( int count ) { } void setItemCount ( int count , int hParent , int hItem ) { } void setItemHeight ( int itemHeight ) { } public void setLinesVisible ( boolean show ) { } int scrolledHandle ( ) { } void select ( int hItem , TVITEM tvItem ) { } public void select ( TreeItem item ) { } public void selectAll ( ) { } Event sendEraseItemEvent ( TreeItem item , NMTTCUSTOMDRAW nmcd , int column , RECT cellRect ) { }

Fix:
while ( ( index <= count ) && ( hItem != 0 ) ) {