Buggy code:
void resetVisibleRegion ( int control ) { } public void setInsertMark ( TreeItem item , boolean before ) { } public void selectAll ( ) { } void setBackground ( float [ ] color ) { } int setBounds ( int x , int y , int width , int height , boolean move , boolean resize , boolean events ) { } public void setColumnOrder ( int [ ] order ) { } void setFontStyle ( Font font ) { } public void setHeaderVisible ( boolean show ) { } public void setItemCount ( int count ) { } void setItemCount ( TreeItem parentItem , int count ) { int itemCount = getItemCount ( parentItem ) ; if ( count == itemCount ) return ; setRedraw ( false ) ; int [ ] top = new int [ 1 ] ; int [ ] left = new int [ 1 ] ; OS . GetDataBrowserScrollPosition ( handle , top , left ) ; DataBrowserCallbacks callbacks = new DataBrowserCallbacks ( ) ; OS . GetDataBrowserCallbacks ( handle , callbacks ) ; callbacks . v1_itemNotificationCallback = 0 ; callbacks . v1_itemCompareCallback = 0 ; OS . SetDataBrowserCallbacks ( handle , callbacks ) ; int [ ] ids = ( parentItem == null ) ? childIds : parentItem . childIds ; if ( count < itemCount ) { int index = count ; while ( index < ( ids . length ) ) { int id = ids [ index ] ; if ( id != 0 ) { TreeItem item = _getItem ( id , false ) ; if ( item != null ) item . release ( false ) ; if ( ( parentItem == null ) || ( parentItem . getExpanded ( ) ) ) { if ( ( OS . RemoveDataBrowserItems ( handle , kDataBrowserNoItem , 1 , new int [ ] { id } , 0 ) ) != ( OS . noErr ) ) { break ; } } } index ++ ; } if ( index < ( ids . length ) ) error ( ERROR_ITEM_NOT_REMOVED ) ; int lastIndex = items . length ; for ( int i = items . length ; i > 0 ; i -- ) { if ( ( items [ ( i - 1 ) ] ) != null ) { lastIndex = i ; break ; } } if ( lastIndex < ( ( items . length ) - 4 ) ) { int length = Math . max ( 4 , ( ( ( lastIndex + 3 ) // 4 ) * 4 ) ) ; TreeItem [ ] newItems = new TreeItem [ length ] ; System . arraycopy ( items , 0 , newItems , 0 , Math . min ( items . length , lastIndex ) ) ; } } if ( parentItem != null ) parentItem . itemCount = count ; int length = Math . max ( 4 , ( ( ( count + 3 ) // 4 ) * 4 ) ) ; int [ ] newIds = new int [ length ] ; if ( ids != null ) { System . arraycopy ( ids , 0 , newIds , 0 , Math . min ( count , itemCount ) ) ; } ids = newIds ; if ( parentItem == null ) { childIds = newIds ; } else { parentItem . childIds = newIds ; } if ( count > itemCount ) { if ( ( ( getStyle ( ) ) & ( SWT . VIRTUAL ) ) == 0 ) { int delta = Math . max ( 4 , ( ( ( ( count - itemCount ) + 3 ) // 4 ) * 4 ) ) ; TreeItem [ ] newItems = new TreeItem [ ( items . length ) + delta ] ; System . arraycopy ( items , 0 , newItems , 0 , items . length ) ; items = newItems ; for ( int i = itemCount ; i < count ; i ++ ) { <START_BUG> items [ i ] = new TreeItem ( parentItem , SWT . NONE , i ) ; <END_BUG> } } else { if ( ( parentItem == null ) || ( parentItem . getExpanded ( ) ) ) { int parentID = ( parentItem == null ) ? OS . kDataBrowserNoItem : parentItem . id ; int [ ] addIds = _getIds ( ( count - itemCount ) ) ; if ( ( OS . AddDataBrowserItems ( handle , parentID , addIds . length , addIds , kDataBrowserItemNoProperty ) ) != ( OS . noErr ) ) { error ( ERROR_ITEM_NOT_ADDED ) ; } System . arraycopy ( addIds , 0 , ids , itemCount , addIds . length ) ; } } } callbacks . v1_itemNotificationCallback = display . itemNotificationProc ; callbacks . v1_itemCompareCallback = display . itemCompareProc ; OS . SetDataBrowserCallbacks ( handle , callbacks ) ; setRedraw ( true ) ; if ( ( itemCount == 0 ) && ( parentItem != null ) ) parentItem . redraw ( kDataBrowserNoItem ) ; } void setItemHeight ( int itemHeight ) { } void setItemHeight ( Image image ) { } public void setLinesVisible ( boolean show ) { } public void setRedraw ( boolean redraw ) { } boolean setScrollWidth ( TreeItem item ) { } boolean setScrollWidth ( boolean set ) { } public void setSelection ( TreeItem item ) { } public void setSelection ( TreeItem [ ] items ) { } public void setSortColumn ( TreeColumn column ) { } public void setSortDirection ( int direction ) { } public void setTopItem ( TreeItem item ) { } public void showColumn ( TreeColumn column ) { } public void showItem ( TreeItem item ) { } void showItem ( TreeItem item , boolean scroll ) { } public void showSelection ( ) { }

Fix:
items [ i ] = new TreeItem ( this , parentItem , SWT . NONE , i , true ) ;