Buggy code:
int selectionEnd = ( selection . y ) - lineOffset ; if ( styledText . getBlockSelection ( ) ) { selectionStart = selectionEnd = 0 ; } Rectangle client = styledText . getClientArea ( ) ; Color lineBackground = getLineBackground ( lineIndex , null ) ; StyledTextEvent event = styledText . getLineBackgroundData ( lineOffset , line ) ; if ( ( event != null ) && ( ( event . lineBackground ) != null ) ) lineBackground = event . lineBackground ; int height = layout . getBounds ( ) . height ; if ( lineBackground != null ) { gc . setBackground ( lineBackground ) ; gc . fillRectangle ( client . x , paintY , client . width , height ) ; } else { gc . setBackground ( widgetBackground ) ; styledText . drawBackground ( gc , client . x , paintY , client . width , height ) ; } gc . setForeground ( widgetForeground ) ; if ( ( selectionStart == selectionEnd ) || ( ( selectionEnd <= 0 ) && ( selectionStart > ( lineLength - 1 ) ) ) ) { layout . draw ( gc , paintX , paintY ) ; } else { int start = Math . max ( 0 , selectionStart ) ; int end = Math . min ( lineLength , selectionEnd ) ; Color selectionFg = styledText . getSelectionForeground ( ) ; Color selectionBg = styledText . getSelectionBackground ( ) ; int flags ; if ( ( ( styledText . getStyle ( ) ) & ( SWT . FULL_SELECTION ) ) != 0 ) { flags = SWT . FULL_SELECTION ; } else { flags = SWT . DELIMITER_SELECTION ; } if ( ( selectionStart <= lineLength ) && ( lineLength < selectionEnd ) ) { flags |= SWT . LAST_LINE_SELECTION ; } layout . draw ( gc , paintX , paintY , start , ( end - 1 ) , selectionFg , selectionBg , flags ) ; } Bullet bullet = null ; int bulletIndex = - 1 ; if ( ( bullets ) != null ) { if ( ( bulletsIndices ) != null ) { int index = lineIndex - ( topIndex ) ; if ( ( 0 <= index ) && ( index < ( StyledTextRenderer . CACHE_SIZE ) ) ) { bullet = bullets [ index ] ; bulletIndex = bulletsIndices [ index ] ; } } else { for ( int i = 0 ; i < ( bullets . length ) ; i ++ ) { bullet = bullets [ i ] ; bulletIndex = bullet . indexOf ( lineIndex ) ; if ( bulletIndex != ( - 1 ) ) break ; } } } if ( ( bulletIndex != ( - 1 ) ) && ( bullet != null ) ) { FontMetrics metrics = layout . getLineMetrics ( 0 ) ; int lineAscent = ( metrics . getAscent ( ) ) + ( metrics . getLeading ( ) ) ; if ( ( bullet . type ) == ( ST . BULLET_CUSTOM ) ) { bullet . style . start = lineOffset ; styledText . paintObject ( gc , paintX , paintY , lineAscent , metrics . getDescent ( ) , bullet . style , bullet , bulletIndex ) ; } else { drawBullet ( bullet , gc , paintX , paintY , bulletIndex , lineAscent , metrics . getDescent ( ) ) ; } } TextStyle [ ] styles = layout . getStyles ( ) ; int [ ] ranges = null ; for ( int i = 0 ; i < ( styles . length ) ; i ++ ) { if ( ( styles [ i ] . metrics ) != null ) { if ( ranges == null ) ranges = layout . getRanges ( ) ; int start = ranges [ ( i << 1 ) ] ; <START_BUG> int length = ( ranges [ ( ( i << 1 ) + 1 ) ] ) - start ; <END_BUG> Point point = layout . getLocation ( start , false ) ; FontMetrics metrics = layout . getLineMetrics ( layout . getLineIndex ( start ) ) ; StyleRange style = ( ( StyleRange ) ( ( ( StyleRange ) ( styles [ i ] ) ) . clone ( ) ) ) ; style . start = start + lineOffset ; style . length = length ; int lineAscent = ( metrics . getAscent ( ) ) + ( metrics . getLeading ( ) ) ; styledText . paintObject ( gc , ( ( point . x ) + paintX ) , ( ( point . y ) + paintY ) , lineAscent , metrics . getDescent ( ) , style , null , 0 ) ; } } disposeTextLayout ( layout ) ; return height ; } int getBaseline ( ) { } Font getFont ( int style ) { } FontData [ ] getFontData ( int style ) { } int getHeight ( ) { } boolean hasLink ( int offset ) { } int getLineAlignment ( int index , int defaultAlignment ) { } Color getLineBackground ( int index , Color defaultBackground ) { } Bullet getLineBullet ( int index , Bullet defaultBullet ) { } int getLineHeight ( ) { } int getLineHeight ( int lineIndex ) { } int getLineIndent ( int index , int defaultIndent ) { } int getLineWrapIndent ( int index , int defaultWrapIndent ) { } boolean getLineJustify ( int index , boolean defaultJustify ) { } int [ ] getLineTabStops ( int index , int [ ] defaultTabStops ) { } int getRangeIndex ( int offset , int low , int high ) { } int [ ] getRanges ( int start , int length ) { } StyleRange [ ] getStyleRanges ( int start , int length , boolean includeRanges ) { } StyleRange getStyleRange ( StyleRange style ) { }

Fix:
int length = ( ( ranges [ ( ( i << 1 ) + 1 ) ] ) - start ) + 1 ;