Buggy code:
public final class TextLayout extends Resource { NSTextStorage textStorage ; NSLayoutManager layoutManager ; NSTextContainer textContainer ; Font font ; String text ; TextLayout . StyleItem [ ] styles ; int spacing ; int ascent ; int descent ; int indent ; boolean justify ; int alignment ; int [ ] tabs ; int [ ] segments ; int wrapWidth ; int orientation ; int [ ] lineOffsets ; NSRect [ ] lineBounds ; static final int UNDERLINE_THICK = 1 << 16 ; static class StyleItem { TextStyle style ; int start ; public String toString ( ) { } } public TextLayout ( Device device ) { } void checkLayout ( ) { } void computeRuns ( ) { } void destroy ( ) { } public void draw ( GC gc , int x , int y ) { } public void draw ( GC gc , int x , int y , int selectionStart , int selectionEnd , Color selectionForeground , Color selectionBackground ) { } public void draw ( GC gc , int x , int y , int selectionStart , int selectionEnd , Color selectionForeground , Color selectionBackground , int flags ) { } void freeRuns ( ) { } public int getAlignment ( ) { } public int getAscent ( ) { } public Rectangle getBounds ( ) { } public Rectangle getBounds ( int start , int end ) { } public int getDescent ( ) { } public Font getFont ( ) { } public int getIndent ( ) { } public boolean getJustify ( ) { } public int getLevel ( int offset ) { } public int [ ] getLineOffsets ( ) { } public int getLineIndex ( int offset ) { } public Rectangle getLineBounds ( int lineIndex ) { } public int getLineCount ( ) { } public FontMetrics getLineMetrics ( int lineIndex ) { } public Point getLocation ( int offset , boolean trailing ) { } public int getNextOffset ( int offset , int movement ) { } int _getOffset ( int offset , int movement , boolean forward ) { checkLayout ( ) ; computeRuns ( ) ; int length = text . length ( ) ; if ( ! ( ( 0 <= offset ) && ( offset <= length ) ) ) SWT . error ( ERROR_INVALID_RANGE ) ; if ( length == 0 ) return 0 ; offset = translateOffset ( offset ) ; switch ( movement ) { case SWT . MOVEMENT_CLUSTER : case SWT . MOVEMENT_CHAR : { if ( forward ) { offset ++ ; } else { offset -- ; } <START_BUG> return untranslateOffset ( offset ) ; <END_BUG> } case SWT . MOVEMENT_WORD : { return untranslateOffset ( textStorage . nextWordFromIndex ( offset , forward ) ) ; } case SWT . MOVEMENT_WORD_END : { NSRange range = textStorage . doubleClickAtIndex ( ( length == offset ? length - 1 : offset ) ) ; return untranslateOffset ( ( ( range . location ) + ( range . length ) ) ) ; } case SWT . MOVEMENT_WORD_START : { NSRange range = textStorage . doubleClickAtIndex ( ( length == offset ? length - 1 : offset ) ) ; return untranslateOffset ( range . location ) ; } default : break ; } return - 1 ; } public int getOffset ( Point point , int [ ] trailing ) { } public int getOffset ( int x , int y , int [ ] trailing ) { } public int getOrientation ( ) { } public int getPreviousOffset ( int index , int movement ) { } public int [ ] getRanges ( ) { } public int [ ] getSegments ( ) { } public int getSpacing ( ) { } public TextStyle getStyle ( int offset ) { } public TextStyle [ ] getStyles ( ) { } public int [ ] getTabs ( ) { } public String getText ( ) { } public int getWidth ( ) { } public boolean isDisposed ( ) { } public void setAlignment ( int alignment ) { } public void setAscent ( int ascent ) { } public void setDescent ( int descent ) { } public void setFont ( Font font ) { } public void setIndent ( int indent ) { } public void setJustify ( boolean justify ) { } public void setOrientation ( int orientation ) { } public void setSegments ( int [ ] segments ) { } public void setSpacing ( int spacing ) { } public void setStyle ( TextStyle style , int start , int end ) { } public void setTabs ( int [ ] tabs ) { } public void setText ( String text ) { } public void setWidth ( int width ) { } public String toString ( ) { } int translateOffset ( int offset ) { } int untranslateOffset ( int offset ) { } }

Fix:
return Math . max ( 0 , Math . min ( length , untranslateOffset ( offset ) ) ) ;