Buggy code:
public class Text extends Scrollable { char echoCharacter ; boolean ignoreChange ; String hiddenText ; int drawCount ; static final boolean IsGB18030 ; public static final int LIMIT ; public static final String DELIMITER ; public Text ( Composite parent , int style ) { } public void addModifyListener ( ModifyListener listener ) { } public void addSelectionListener ( SelectionListener listener ) { } public void addVerifyListener ( VerifyListener listener ) { } public void append ( String string ) { } static int checkStyle ( int style ) { } public void clearSelection ( ) { } public Point computeSize ( int wHint , int hHint , boolean changed ) { } public Rectangle computeTrim ( int x , int y , int width , int height ) { } public void copy ( ) { } void createHandle ( int index ) { } ScrollBar createScrollBar ( int type ) { } void createWidget ( int index ) { } public void cut ( ) { } int defaultBackground ( ) { } Font defaultFont ( ) { } int defaultForeground ( ) { } public int getCaretLineNumber ( ) { } public Point getCaretLocation ( ) { } public int getCaretPosition ( ) { } public int getCharCount ( ) { } public boolean getDoubleClickEnabled ( ) { } public char getEchoChar ( ) { } public boolean getEditable ( ) { } public int getLineCount ( ) { } public String getLineDelimiter ( ) { } public int getLineHeight ( ) { } int getLineNumber ( int position ) { } int getNavigationType ( ) { } public int getOrientation ( ) { } public Point getSelection ( ) { } public int getSelectionCount ( ) { } public String getSelectionText ( ) { } public int getTabs ( ) { } public String getText ( ) { } public String getText ( int start , int end ) { } public int getTextLimit ( ) { } public int getTopIndex ( ) { } public int getTopPixel ( ) { } boolean hasIMSupport ( ) { } void hookEvents ( ) { } int inputContext ( ) { } public void insert ( String string ) { checkWidget ( ) ; if ( string == null ) error ( ERROR_NULL_ARGUMENT ) ; int [ ] start = new int [ 1 ] ; int [ ] end = new int [ 1 ] ; OS . XmTextGetSelectionPosition ( handle , start , end ) ; if ( ( start [ 0 ] ) == ( end [ 0 ] ) ) { start [ 0 ] = end [ 0 ] = OS . XmTextGetInsertionPosition ( handle ) ; } byte [ ] buffer = Converter . wcsToMbcs ( getCodePage ( ) , string , true ) ; boolean warnings = display . getWarnings ( ) ; display . setWarnings ( false ) ; OS . XmTextReplace ( handle , start [ 0 ] , end [ 0 ] , buffer ) ; <START_BUG> int position = ( ( start [ 0 ] ) + ( buffer . length ) ) - 1 ; <END_BUG> OS . XmTextSetInsertionPosition ( handle , position ) ; display . setWarnings ( warnings ) ; } void overrideTranslations ( ) { } public void paste ( ) { } void releaseWidget ( ) { } public void removeModifyListener ( ModifyListener listener ) { } public void removeSelectionListener ( SelectionListener listener ) { } public void removeVerifyListener ( VerifyListener listener ) { } boolean sendIMKeyEvent ( int type , XKeyEvent xEvent ) { } public void selectAll ( ) { } boolean setBounds ( int x , int y , int width , int height , boolean move , boolean resize ) { } public void setDoubleClickEnabled ( boolean doubleClick ) { } public void setEchoChar ( char echo ) { } public void setEditable ( boolean editable ) { } public void setOrientation ( int orientation ) { } public void setRedraw ( boolean redraw ) { } public void setSelection ( int start ) { } public void setSelection ( int start , int end ) { } public void setSelection ( Point selection ) { } public void setTabs ( int tabs ) { } public void setText ( String string ) { } public void setTextLimit ( int limit ) { } public void setTopIndex ( int index ) { } public void showSelection ( ) { } int traversalCode ( int key , XKeyEvent xEvent ) { } int xFocusIn ( XFocusChangeEvent xEvent ) { } int xFocusOut ( XFocusChangeEvent xEvent ) { } int XmNactivateCallback ( int w , int client_data , int call_data ) { } int XmNmodifyVerifyCallback ( int w , int client_data , int call_data ) { } int XmNvalueChangedCallback ( int w , int client_data , int call_data ) { } }

Fix:
int position = ( start [ 0 ] ) + ( Math . max ( 0 , ( ( buffer . length ) - 1 ) ) ) ;