Buggy code:
int selectionForeground ; int headerToolTipHandle ; int itemToolTipHandle ; static final int INSET = 3 ; static final int GRID_WIDTH = 1 ; static final int SORT_WIDTH = 10 ; static final int HEADER_MARGIN = 12 ; static final int HEADER_EXTRA = 3 ; static final int INCREMENT = 5 ; static final int EXPLORER_EXTRA = 2 ; static final boolean EXPLORER_THEME = true ; static final int TreeProc ; static final TCHAR TreeClass = new TCHAR ( 0 , OS . WC_TREEVIEW , true ) ; static final int HeaderProc ; static final TCHAR HeaderClass = new TCHAR ( 0 , OS . WC_HEADER , true ) ; public Tree ( Composite parent , int style ) { } static int checkStyle ( int style ) { } void _addListener ( int eventType , Listener listener ) { } TreeItem _getItem ( int hItem ) { } TreeItem _getItem ( int hItem , int id ) { } void _setBackgroundPixel ( int newPixel ) { } public void addSelectionListener ( SelectionListener listener ) { } public void addTreeListener ( TreeListener listener ) { } int borderHandle ( ) { } LRESULT CDDS_ITEMPOSTPAINT ( NMTVCUSTOMDRAW nmcd , int wParam , int lParam ) { } LRESULT CDDS_ITEMPREPAINT ( NMTVCUSTOMDRAW nmcd , int wParam , int lParam ) { } LRESULT CDDS_POSTPAINT ( NMTVCUSTOMDRAW nmcd , int wParam , int lParam ) { } LRESULT CDDS_PREPAINT ( NMTVCUSTOMDRAW nmcd , int wParam , int lParam ) { } int callWindowProc ( int hwnd , int msg , int wParam , int lParam ) { } void checkBuffered ( ) { } boolean checkData ( TreeItem item , boolean redraw ) { } boolean checkData ( TreeItem item , int index , boolean redraw ) { } boolean checkHandle ( int hwnd ) { } boolean checkScroll ( int hItem ) { } protected void checkSubclass ( ) { } public void clear ( int index , boolean all ) { } void clear ( int hItem , TVITEM tvItem ) { } public void clearAll ( boolean all ) { } void clearAll ( int hItem , TVITEM tvItem , boolean all ) { } int CompareFunc ( int lParam1 , int lParam2 , int lParamSort ) { } public Point computeSize ( int wHint , int hHint , boolean changed ) { checkWidget ( ) ; int width = 0 ; int height = 0 ; if ( ( hwndHeader ) != 0 ) { HDITEM hdItem = new HDITEM ( ) ; hdItem . mask = OS . HDI_WIDTH ; int count = ( ( int ) ( OS . SendMessage ( hwndHeader , HDM_GETITEMCOUNT , 0 , 0 ) ) ) ; for ( int i = 0 ; i < count ; i ++ ) { OS . SendMessage ( hwndHeader , HDM_GETITEM , i , hdItem ) ; width += hdItem . cxy ; } RECT rect = new RECT ( ) ; OS . GetWindowRect ( hwndHeader , rect ) ; height += ( rect . bottom ) - ( rect . top ) ; } RECT rect = new RECT ( ) ; int hItem = OS . SendMessage ( handle , TVM_GETNEXTITEM , TVGN_ROOT , 0 ) ; while ( hItem != 0 ) { if ( ( ( ( style ) & ( SWT . VIRTUAL ) ) == 0 ) && ( ! ( painted ) ) ) { TVITEM tvItem = new TVITEM ( ) ; tvItem . mask = ( OS . TVIF_HANDLE ) | ( OS . TVIF_TEXT ) ; tvItem . hItem = hItem ; tvItem . pszText = OS . LPSTR_TEXTCALLBACK ; ignoreCustomDraw = true ; OS . SendMessage ( handle , TVM_SETITEM , 0 , tvItem ) ; ignoreCustomDraw = false ; } if ( OS . TreeView_GetItemRect ( handle , hItem , rect , true ) ) { width = Math . max ( width , rect . right ) ; height += ( rect . bottom ) - ( rect . top ) ; } <START_BUG> hItem = OS . SendMessage ( handle , TVM_GETNEXTITEM , TVGN_NEXT , hItem ) ; <END_BUG> } if ( width == 0 ) width = DEFAULT_WIDTH ; if ( height == 0 ) height = DEFAULT_HEIGHT ; if ( wHint != ( SWT . DEFAULT ) ) width = wHint ; if ( hHint != ( SWT . DEFAULT ) ) height = hHint ; int border = getBorderWidth ( ) ; width += border * 2 ; height += border * 2 ; if ( ( ( style ) & ( SWT . V_SCROLL ) ) != 0 ) { width += OS . GetSystemMetrics ( SM_CXVSCROLL ) ; } if ( ( ( style ) & ( SWT . H_SCROLL ) ) != 0 ) { height += OS . GetSystemMetrics ( SM_CYHSCROLL ) ; } return new Point ( width , height ) ; } void createHandle ( ) { } 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 deselectAll ( ) { } void destroyItem ( TreeColumn column ) { } void destroyItem ( TreeItem item , int hItem ) { } void enableDrag ( boolean enabled ) { } void enableWidget ( boolean enabled ) { } int findIndex ( int hFirstItem , int hItem ) { } Widget findItem ( int hItem ) { } int findItem ( int hFirstItem , int index ) { } TreeItem getFocusItem ( ) { } public int getGridLineWidth ( ) { }

Fix:
hItem = OS . SendMessage ( handle , TVM_GETNEXTITEM , TVGN_NEXTVISIBLE , hItem ) ;