Buggy code:
static final int SEGMENTS = 1 << 5 ; static class LineInfo { int flags ; Color background ; int alignment ; int indent ; boolean justify ; int [ ] segments ; public LineInfo ( ) { } public LineInfo ( StyledTextRenderer . LineInfo info ) { } } StyledTextRenderer ( Device device , StyledText styledText ) { } int addMerge ( int [ ] mergeRanges , StyleRange [ ] mergeStyles , int mergeCount , int modifyStart , int modifyEnd ) { } int addMerge ( StyleRange [ ] mergeStyles , int mergeCount , int modifyStart , int modifyEnd ) { } void calculate ( int startLine , int lineCount ) { } void calculateClientArea ( ) { } void calculateIdle ( ) { } void clearLineBackground ( int startLine , int count ) { } void clearLineStyle ( int startLine , int count ) { } void copyInto ( StyledTextRenderer renderer ) { } void dispose ( ) { } void disposeTextLayout ( TextLayout layout ) { } void drawBullet ( Bullet bullet , GC gc , int paintX , int paintY , int index , int lineAscent , int lineDescent ) { } int drawLine ( int lineIndex , int paintX , int paintY , GC gc , Color widgetBackground , Color widgetForeground ) { } int getBaseline ( ) { } Font getFont ( int style ) { } FontData [ ] getFontData ( int style ) { } int getHeight ( ) { } 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 ) { } boolean getLineJustify ( int index , boolean defaultJustify ) { } int [ ] getLineSegments ( int index , int [ ] defaultSegments ) { } int getRangeIndex ( int offset , int low , int high ) { } int [ ] getRanges ( int start , int length ) { int [ ] newRanges ; int end = ( start + length ) - 1 ; if ( ( ranges ) != null ) { int rangeCount = ( styleCount ) << 1 ; int rangeStart = getRangeIndex ( start , ( - 1 ) , rangeCount ) ; if ( rangeStart >= rangeCount ) return null ; if ( ( ranges [ rangeStart ] ) > end ) return null ; int rangeEnd = Math . min ( ( rangeCount - 2 ) , ( ( getRangeIndex ( end , ( rangeStart - 1 ) , rangeCount ) ) + 1 ) ) ; newRanges = new int [ ( rangeEnd - rangeStart ) + 2 ] ; System . arraycopy ( ranges , rangeStart , newRanges , 0 , newRanges . length ) ; } else { int rangeStart = getRangeIndex ( start , ( - 1 ) , styleCount ) ; if ( rangeStart >= ( styleCount ) ) return null ; if ( ( styles [ rangeStart ] . start ) > end ) return null ; int rangeEnd = Math . min ( ( ( styleCount ) - 1 ) , getRangeIndex ( end , ( rangeStart - 1 ) , styleCount ) ) ; newRanges = new int [ ( ( rangeEnd - rangeStart ) + 1 ) << 1 ] ; for ( int i = rangeStart , j = 0 ; i <= rangeEnd ; i ++ , j += 2 ) { StyleRange style = styles [ i ] ; newRanges [ j ] = style . start ; newRanges [ ( j + 1 ) ] = style . length ; } } if ( start > ( newRanges [ 0 ] ) ) { newRanges [ 1 ] = ( ( newRanges [ 0 ] ) + ( newRanges [ 1 ] ) ) - start ; newRanges [ 0 ] = start ; } if ( end < ( ( ( newRanges [ ( ( newRanges . length ) - 2 ) ] ) + ( newRanges [ ( ( newRanges . length ) - 1 ) ] ) ) - 1 ) ) { <START_BUG> newRanges [ ( ( newRanges . length ) - 1 ) ] = end - ( newRanges [ ( ( newRanges . length ) - 2 ) ] ) ; <END_BUG> } return newRanges ; } StyleRange [ ] getStyleRanges ( int start , int length , boolean includeRanges ) { } StyleRange getStyleRange ( StyleRange style ) { } TextLayout getTextLayout ( int lineIndex ) { } TextLayout getTextLayout ( int lineIndex , int orientation , int width , int lineSpacing ) { } int getWidth ( ) { } void reset ( ) { } void reset ( int startLine , int lineCount ) { } void setContent ( StyledTextContent content ) { } void setFont ( Font font , int tabs ) { } void setLineAlignment ( int startLine , int count , int alignment ) { } void setLineBackground ( int startLine , int count , Color background ) { } void setLineBullet ( int startLine , int count , Bullet bullet ) { } void setLineIndent ( int startLine , int count , int indent ) { } void setLineJustify ( int startLine , int count , boolean justify ) { } void setLineSegments ( int startLine , int count , int [ ] segments ) { } void setStyleRanges ( int [ ] newRanges , StyleRange [ ] newStyles ) { } void textChanging ( TextChangingEvent event ) { } void updateBullets ( int startLine , int replaceLineCount , int newLineCount , boolean update ) { } void updateRanges ( int start , int replaceCharCount , int newCharCount ) { } }

Fix:
newRanges [ ( ( newRanges . length ) - 1 ) ] = ( end - ( newRanges [ ( ( newRanges . length ) - 2 ) ] ) ) + 1 ;