Buggy code:
public class TableItem extends Item { Table parent ; int index = - 1 ; boolean checked ; boolean grayed ; boolean cached ; String [ ] texts ; int [ ] textWidths = new int [ 1 ] ; int fontHeight ; int [ ] fontHeights ; int imageIndent ; Image [ ] images ; Color foreground ; Color background ; String [ ] displayTexts ; Color [ ] cellForegrounds ; Color [ ] cellBackgrounds ; Font font ; Font [ ] cellFonts ; static final int MARGIN_TEXT = 3 ; public TableItem ( Table parent , int style ) { } public TableItem ( Table parent , int style , int index ) { } TableItem ( Table parent , int style , int index , boolean notifyParent ) { } void addColumn ( TableColumn column ) { } static Table checkNull ( Table table ) { } void clear ( ) { } void computeDisplayText ( int columnIndex , GC gc ) { int columnCount = parent . columns . length ; if ( columnCount == 0 ) { String text = getText ( 0 ) ; textWidths [ columnIndex ] = gc . stringExtent ( text ) . x ; return ; } TableColumn column = parent . columns [ columnIndex ] ; int availableWidth = ( ( column . width ) - ( 2 * ( parent . getCellPadding ( ) ) ) ) - ( 2 * ( TableItem . MARGIN_TEXT ) ) ; if ( columnIndex == 0 ) { availableWidth -= parent . col0ImageWidth ; if ( ( parent . col0ImageWidth ) > 0 ) availableWidth -= Table . MARGIN_IMAGE ; if ( ( ( parent . style ) & ( SWT . CHECK ) ) != 0 ) { availableWidth -= parent . checkboxBounds . width ; availableWidth -= Table . MARGIN_IMAGE ; } } else { Image image = getImage ( columnIndex ) ; if ( image != null ) { availableWidth -= image . getBounds ( ) . width ; availableWidth -= Table . MARGIN_IMAGE ; } } String text = getText ( columnIndex ) ; int textWidth = gc . stringExtent ( text ) . x ; if ( textWidth <= availableWidth ) { displayTexts [ columnIndex ] = text ; textWidths [ columnIndex ] = textWidth ; return ; } int ellipsisWidth = gc . stringExtent ( ELLIPSIS ) . x ; availableWidth -= ellipsisWidth ; if ( availableWidth <= 0 ) { displayTexts [ columnIndex ] = Table . ELLIPSIS ; textWidths [ columnIndex ] = ellipsisWidth ; return ; } <START_BUG> int index = availableWidth // ( gc . getFontMetrics ( ) . getAverageCharWidth ( ) ) ; <END_BUG> textWidth = gc . stringExtent ( text . substring ( 0 , index ) ) . x ; if ( availableWidth == textWidth ) { displayTexts [ columnIndex ] = ( text . substring ( 0 , index ) ) + ( Table . ELLIPSIS ) ; textWidths [ columnIndex ] = textWidth + ellipsisWidth ; return ; } if ( availableWidth < textWidth ) { do { index -- ; if ( index < 0 ) { displayTexts [ columnIndex ] = Table . ELLIPSIS ; textWidths [ columnIndex ] = ellipsisWidth ; return ; } text = text . substring ( 0 , index ) ; textWidth = gc . stringExtent ( text ) . x ; } while ( availableWidth < textWidth ) ; displayTexts [ columnIndex ] = text + ( Table . ELLIPSIS ) ; textWidths [ columnIndex ] = textWidth + ellipsisWidth ; return ; } int previousWidth = 0 ; while ( textWidth < availableWidth ) { index ++ ; previousWidth = textWidth ; textWidth = gc . stringExtent ( text . substring ( 0 , index ) ) . x ; } displayTexts [ columnIndex ] = ( text . substring ( 0 , ( index - 1 ) ) ) + ( Table . ELLIPSIS ) ; textWidths [ columnIndex ] = previousWidth + ellipsisWidth ; } void computeDisplayTexts ( GC gc ) { } public void dispose ( ) { } void dispose ( boolean notifyParent ) { } public Color getBackground ( ) { } public Color getBackground ( int columnIndex ) { } Rectangle getBounds ( ) { } public Rectangle getBounds ( int columnIndex ) { } Rectangle getCellBounds ( int columnIndex ) { } Rectangle getCheckboxBounds ( ) { } public boolean getChecked ( ) { } int getContentWidth ( int columnIndex ) { } int getContentX ( int columnIndex ) { } String getDisplayText ( int columnIndex ) { } Rectangle getFocusBounds ( ) { } public Font getFont ( ) { } public Font getFont ( int columnIndex ) { } int getFontHeight ( ) { } int getFontHeight ( int columnIndex ) { } public Color getForeground ( ) { } public Color getForeground ( int columnIndex ) { } public boolean getGrayed ( ) { } Rectangle getHitBounds ( ) { } public Image getImage ( ) { } public Image getImage ( int columnIndex ) { } public Rectangle getImageBounds ( int columnIndex ) { } public int getImageIndent ( ) { } public Table getParent ( ) { } int getPreferredWidth ( int columnIndex ) { } public String getText ( ) { } public String getText ( int columnIndex ) { } int getTextX ( int columnIndex ) { } boolean isSelected ( ) { } void paint ( GC gc , TableColumn column , boolean paintCellContent ) { } void recomputeTextWidths ( GC gc ) { } void redrawItem ( ) { } void removeColumn ( TableColumn column , int index ) { } public void setBackground ( Color value ) { } public void setBackground ( int columnIndex , Color value ) { } public void setChecked ( boolean value ) { } public void setFont ( Font value ) { }

Fix:
int index = Math . min ( ( availableWidth // ( gc . getFontMetrics ( ) . getAverageCharWidth ( ) ) ) , text . length ( ) ) ;