Buggy code:
public class TextEditor { Display display ; Shell shell ; CoolBar coolBar ; StyledText styledText ; Label statusBar ; ToolItem boldControl ; ToolItem italicControl ; ToolItem leftAlignmentItem ; ToolItem centerAlignmentItem ; ToolItem rightAlignmentItem ; ToolItem justifyAlignmentItem ; ToolItem blockSelectionItem ; Combo fontNameControl ; Combo fontSizeControl ; MenuItem underlineSingleItem ; MenuItem underlineDoubleItem ; MenuItem underlineErrorItem ; MenuItem underlineSquiggleItem ; MenuItem borderSolidItem ; MenuItem borderDashItem ; MenuItem borderDotItem ; boolean insert = true ; StyleRange [ ] selectedRanges ; int [ ] imageOffsets = new int [ 0 ] ; Image [ ] images = new Image [ 0 ] ; Control [ ] controls = new Control [ 0 ] ; int [ ] controlOffsets = new int [ 0 ] ; int newCharCount ; int start ; String fileName = null ; int styleState ; Image iBold ; Image iItalic ; Image iUnderline ; Image iStrikeout ; Image iLeftAlignment ; Image iRightAlignment ; Image iCenterAlignment ; Image iJustifyAlignment ; Image iCopy ; Image iCut ; Image iPaste ; Image iSpacing ; Image iIndent ; Image iTextForeground ; Image iTextBackground ; Image iBaselineUp ; Image iBaselineDown ; Image iBulletList ; Image iNumberedList ; Image iBlockSelection ; Image iBorderStyle ; Font font ; Font textFont ; Color textForeground ; Color textBackground ; Color strikeoutColor ; Color underlineColor ; Color borderColor ; static final int BULLET_WIDTH = 40 ; static final int MARGIN = 5 ; static final int BOLD = SWT . BOLD ; static final int ITALIC = SWT . ITALIC ; static final int FONT_STYLE = ( TextEditor . BOLD ) | ( TextEditor . ITALIC ) ; static final int STRIKEOUT = 1 << 3 ; static final int TEXT_FOREGROUND = 1 << 4 ; static final int TEXT_BACKGROUND = 1 << 5 ; static final int FONT = 1 << 6 ; static final int BASELINE_UP = 1 << 7 ; static final int BASELINE_DOWN = 1 << 8 ; static final int UNDERLINE_SINGLE = 1 << 9 ; static final int UNDERLINE_DOUBLE = 1 << 10 ; static final int UNDERLINE_ERROR = 1 << 11 ; static final int UNDERLINE_SQUIGGLE = 1 << 12 ; static final int UNDERLINE = ( ( ( TextEditor . UNDERLINE_SINGLE ) | ( TextEditor . UNDERLINE_DOUBLE ) ) | ( TextEditor . UNDERLINE_SQUIGGLE ) ) | ( TextEditor . UNDERLINE_ERROR ) ; static final int BORDER_SOLID = 1 << 13 ; static final int BORDER_DASH = 1 << 14 ; static final int BORDER_DOT = 1 << 15 ; static final int BORDER = ( ( TextEditor . BORDER_SOLID ) | ( TextEditor . BORDER_DASH ) ) | ( TextEditor . BORDER_DOT ) ; static final boolean SAMPLE_TEXT = false ; static final ResourceBundle resources = ResourceBundle . getBundle ( "examples_texteditor" ) ; static String getResourceString ( String key ) { } public static void main ( String [ ] args ) { } public TextEditor ( Display display ) { } void addControl ( Control control ) { } void addImage ( Image image ) { } void createMenuBar ( ) { } void createPopup ( ) { } void createToolBar ( ) { <START_BUG> coolBar = new CoolBar ( shell , SWT . NONE ) ; <END_BUG> ToolBar styleToolBar = new ToolBar ( coolBar , SWT . FLAT ) ; boldControl = new ToolItem ( styleToolBar , SWT . CHECK ) ; boldControl . setImage ( iBold ) ; boldControl . setToolTipText ( TextEditor . getResourceString ( "Bold" ) ) ; boldControl . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent event ) { setStyle ( TextEditor . BOLD ) ; } } ) ; italicControl = new ToolItem ( styleToolBar , SWT . CHECK ) ; italicControl . setImage ( iItalic ) ; italicControl . setToolTipText ( TextEditor . getResourceString ( "Italic" ) ) ; italicControl . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent event ) { setStyle ( TextEditor . ITALIC ) ; } } ) ; final Menu underlineMenu = new Menu ( shell , SWT . POP_UP ) ; underlineSingleItem = new MenuItem ( underlineMenu , SWT . RADIO ) ; underlineSingleItem . setText ( TextEditor . getResourceString ( "Single_menuitem" ) ) ; underlineSingleItem . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent event ) { if ( underlineSingleItem . getSelection ( ) ) { setStyle ( TextEditor . UNDERLINE_SINGLE ) ; } } } ) ; underlineSingleItem . setSelection ( true ) ; underlineDoubleItem = new MenuItem ( underlineMenu , SWT . RADIO ) ; underlineDoubleItem . setText ( TextEditor . getResourceString ( "Double_menuitem" ) ) ; underlineDoubleItem . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent event ) { if ( underlineDoubleItem . getSelection ( ) ) { setStyle ( TextEditor . UNDERLINE_DOUBLE ) ; } } } ) ; underlineSquiggleItem = new MenuItem ( underlineMenu , SWT . RADIO ) ; underlineSquiggleItem . setText ( TextEditor . getResourceString ( "Squiggle_menuitem" ) ) ; underlineSquiggleItem . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent event ) { if ( underlineSquiggleItem . getSelection ( ) ) { setStyle ( TextEditor . UNDERLINE_SQUIGGLE ) ; } } } ) ; underlineErrorItem = new MenuItem ( underlineMenu , SWT . RADIO ) ; underlineErrorItem . setText ( TextEditor . getResourceString ( "Error_menuitem" ) ) ; underlineErrorItem . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent event ) { if ( underlineErrorItem . getSelection ( ) ) { setStyle ( TextEditor . UNDERLINE_ERROR ) ; } } } ) ; MenuItem underlineColorItem = new MenuItem ( underlineMenu , SWT . PUSH ) ; underlineColorItem . setText ( TextEditor . getResourceString ( "Color_menuitem" ) ) ; underlineColorItem . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent event ) { ColorDialog dialog = new ColorDialog ( shell ) ;

Fix:
coolBar = new CoolBar ( shell , SWT . FLAT ) ;