Buggy code:
public class Snippet334 { static final String text = "line<seq2seq4repair_space>one\nline<seq2seq4repair_space>two\nline<seq2seq4repair_space>three" ; static Display display ; static Shell shell ; static Canvas canvas ; public static void main ( String [ ] arg ) { Snippet334 . display = new Display ( ) ; Snippet334 . shell = new Shell ( Snippet334 . display ) ; Snippet334 . shell . setLayout ( new GridLayout ( 2 , false ) ) ; Label label = new Label ( Snippet334 . shell , SWT . NONE ) ; label . setText ( "Test:" ) ; Snippet334 . canvas = new Canvas ( Snippet334 . shell , ( ( SWT . MULTI ) | ( SWT . BORDER ) ) ) ; final Caret caret = new Caret ( Snippet334 . canvas , SWT . NONE ) ; Snippet334 . canvas . addPaintListener ( new PaintListener ( ) { public void paintControl ( PaintEvent e ) { GC gc = e . gc ; gc . drawText ( Snippet334 . text , 10 , 10 ) ; caret . setBounds ( 10 , 10 , 2 , gc . getFontMetrics ( ) . getHeight ( ) ) ; Rectangle rect = Snippet334 . canvas . getClientArea ( ) ; if ( Snippet334 . canvas . isFocusControl ( ) ) { gc . drawFocus ( rect . x , rect . y , rect . width , rect . height ) ; } } } ) ; Snippet334 . canvas . addTraverseListener ( new TraverseListener ( ) { public void keyTraversed ( TraverseEvent e ) { switch ( e . detail ) { case SWT . TRAVERSE_TAB_NEXT : case SWT . TRAVERSE_TAB_PREVIOUS : e . doit = true ; break ; } } } ) ; Snippet334 . canvas . addKeyListener ( new KeyAdapter ( ) { public void keyPressed ( KeyEvent e ) { } } ) ; Snippet334 . canvas . addFocusListener ( new FocusAdapter ( ) { public void focusGained ( FocusEvent e ) { Snippet334 . canvas . redraw ( ) ; } public void focusLost ( FocusEvent e ) { Snippet334 . canvas . redraw ( ) ; } } ) ; Snippet334 . canvas . addMouseListener ( new MouseAdapter ( ) { public void mouseDown ( MouseEvent e ) { Snippet334 . canvas . setFocus ( ) ; } } ) ; Accessible acc = Snippet334 . canvas . getAccessible ( ) ; acc . addRelation ( RELATION_LABELLED_BY , label . getAccessible ( ) ) ; acc . addAccessibleControlListener ( new AccessibleControlAdapter ( ) { public void getRole ( AccessibleControlEvent e ) { e . detail = ACC . ROLE_TEXT ; } public void getLocation ( AccessibleControlEvent e ) { Rectangle rect = Snippet334 . canvas . getBounds ( ) ; Point pt = Snippet334 . shell . toDisplay ( rect . x , rect . y ) ; e . x = pt . x ; e . y = pt . y ; e . width = rect . width ; e . height = rect . height ; } public void getValue ( AccessibleControlEvent e ) { e . result = Snippet334 . text ; } public void getFocus ( AccessibleControlEvent e ) { e . childID = ACC . CHILDID_SELF ; } public void getChildCount ( AccessibleControlEvent e ) { e . detail = 0 ; } public void getState ( AccessibleControlEvent e ) { <START_BUG> e . detail = ( ( ACC . STATE_NORMAL ) | ( ACC . STATE_FOCUSABLE ) ) | ( ACC . STATE_ENABLED ) ; <END_BUG> if ( Snippet334 . canvas . isFocusControl ( ) ) e . detail |= ( ACC . STATE_FOCUSED ) | ( ACC . STATE_SELECTABLE ) ; } } ) ; acc . addAccessibleTextListener ( new AccessibleTextExtendedAdapter ( ) { public void getSelectionRange ( AccessibleTextEvent e ) { e . offset = 0 ; e . length = 4 ; } public void getCaretOffset ( AccessibleTextEvent e ) { e . offset = 0 ; } public void getTextBounds ( AccessibleTextExtendedEvent e ) { GC gc = new GC ( Snippet334 . canvas ) ; Point extent = gc . textExtent ( Snippet334 . text ) ; gc . dispose ( ) ; Rectangle rect = Snippet334 . display . map ( Snippet334 . canvas , null , 10 , 10 , extent . x , extent . y ) ; e . x = rect . x ; e . y = rect . y ; e . width = rect . width ; e . height = rect . height ; } public void getText ( AccessibleTextExtendedEvent e ) { int start = 0 ; int end = Snippet334 . text . length ( ) ; switch ( e . type ) { case ACC . TEXT_BOUNDARY_ALL : start = e . start ; end = e . end ; break ; case ACC . TEXT_BOUNDARY_CHAR : start = ( ( e . count ) >= 0 ) ? ( e . start ) + ( e . count ) : ( e . start ) - ( e . count ) ; start = Math . max ( 0 , Math . min ( end , start ) ) ; end = start ; e . count = start - ( e . start ) ; e . start = start ; e . end = start ; break ; case ACC . TEXT_BOUNDARY_LINE : int offset = ( ( e . count ) <= 0 ) ? e . start : e . end ; offset = Math . min ( offset , Snippet334 . text . length ( ) ) ; int lineCount = 0 ; int index = 0 ; while ( index != ( - 1 ) ) { lineCount ++ ; index = Snippet334 . text . indexOf ( "\n" , index ) ; if ( index != ( - 1 ) ) index ++ ; }

Fix:
e . detail = ( ACC . STATE_NORMAL ) | ( ACC . STATE_FOCUSABLE ) ;