Buggy code:
public String toString ( ) { } } public TextLayout ( Device device ) { } void checkLayout ( ) { } void computeRuns ( ) { } public void dispose ( ) { } 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 ) { } 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 Rectangle getLineBounds ( int lineIndex ) { } public int getLineCount ( ) { } public int getLineIndex ( int offset ) { } public FontMetrics getLineMetrics ( int lineIndex ) { } public int [ ] getLineOffsets ( ) { } public Point getLocation ( int offset , boolean trailing ) { } public int getNextOffset ( int offset , int movement ) { } int _getOffset ( int offset , int movement , boolean forward ) { computeRuns ( ) ; int length = text . length ( ) ; if ( ! ( ( 0 <= offset ) && ( offset <= length ) ) ) SWT . error ( ERROR_INVALID_RANGE ) ; if ( forward && ( offset == length ) ) return length ; if ( ( ! forward ) && ( offset == 0 ) ) return 0 ; int step = ( forward ) ? 1 : - 1 ; if ( ( movement & ( SWT . MOVEMENT_CHAR ) ) != 0 ) return offset + step ; length = segmentsText . length ( ) ; offset = translateOffset ( offset ) ; int lineStart = 0 ; int lineIndex ; for ( lineIndex = 0 ; lineIndex < ( lines . length ) ; lineIndex ++ ) { int lineLength = OS . TextLine_Length ( lines [ lineIndex ] ) ; if ( ( lineStart + lineLength ) > offset ) break ; lineStart += lineLength ; } int line = lines [ lineIndex ] ; int lineLength = OS . TextLine_Length ( line ) ; int lineBreak = OS . TextLine_NewlineLength ( line ) ; while ( ( lineStart <= offset ) && ( offset <= ( lineStart + lineLength ) ) ) { int resultCharHit ; int characterHit = OS . gcnew_CharacterHit ( offset , 0 ) ; if ( forward ) { resultCharHit = OS . TextLine_GetNextCaretCharacterHit ( line , characterHit ) ; } else { resultCharHit = OS . TextLine_GetPreviousCaretCharacterHit ( line , characterHit ) ; } int newOffset = OS . CharacterHit_FirstCharacterIndex ( resultCharHit ) ; int trailing = OS . CharacterHit_TrailingLength ( resultCharHit ) ; OS . GCHandle_Free ( resultCharHit ) ; OS . GCHandle_Free ( characterHit ) ; if ( forward ) { if ( ( newOffset + trailing ) >= ( ( lineStart + lineLength ) - lineBreak ) ) { int lineEnd = lineStart + lineLength ; if ( trailing != 0 ) lineEnd -= lineBreak ; return untranslateOffset ( Math . min ( length , lineEnd ) ) ; } } else { if ( ( newOffset + trailing ) == lineStart ) { if ( lineIndex == 0 ) return 0 ; int lineEnd = 0 ; if ( ( newOffset + trailing ) == offset ) lineEnd = OS . TextLine_NewlineLength ( lines [ ( lineIndex - 1 ) ] ) ; return untranslateOffset ( Math . max ( 0 , ( ( newOffset + trailing ) - lineEnd ) ) ) ; } } offset = newOffset + trailing ; switch ( movement ) { case SWT . MOVEMENT_CLUSTER : <START_BUG> return untranslateOffset ( newOffset ) ; <END_BUG> case SWT . MOVEMENT_WORD : case SWT . MOVEMENT_WORD_START : { if ( offset > 0 ) { boolean letterOrDigit = Compatibility . isLetterOrDigit ( segmentsText . charAt ( offset ) ) ; boolean previousLetterOrDigit = Compatibility . isLetterOrDigit ( segmentsText . charAt ( ( offset - 1 ) ) ) ; if ( ( letterOrDigit != previousLetterOrDigit ) || ( ! letterOrDigit ) ) { if ( ! ( Compatibility . isWhitespace ( segmentsText . charAt ( offset ) ) ) ) { return untranslateOffset ( offset ) ; } } } break ; } case SWT . MOVEMENT_WORD_END : { if ( offset > 0 ) { boolean isLetterOrDigit = Compatibility . isLetterOrDigit ( segmentsText . charAt ( offset ) ) ; boolean previousLetterOrDigit = Compatibility . isLetterOrDigit ( segmentsText . charAt ( ( offset - 1 ) ) ) ; if ( ( ! isLetterOrDigit ) && previousLetterOrDigit ) { return untranslateOffset ( offset ) ; } } break ; } } } return forward ? text . length ( ) : 0 ; } public int getOffset ( Point point , int [ ] trailing ) { } public int getOffset ( int x , int y , int [ ] trailing ) { } public int getOrientation ( ) { } public int getPreviousOffset ( int offset , int movement ) { } public int [ ] getRanges ( ) { } public int [ ] getSegments ( ) { } String getSegmentsText ( ) { } public int getSpacing ( ) { } public TextStyle getStyle ( int offset ) { } public TextStyle [ ] getStyles ( ) { } public int [ ] getTabs ( ) { } int GetTextRun ( int textSourceCharacterIndex ) { } int GetPrecedingText ( int textSourceCharacterIndexLimit ) { } public String getText ( ) { } public int getWidth ( ) { }

Fix:
return untranslateOffset ( offset ) ;