Program: 157342
Project: 157342
Buggy source:
private void handleCharacter(final int primaryCode,final Key key,final int multiTapIndex,int[] nearByKeyCodes){
  if (BuildConfig.DEBUG)   Logger.d(TAG,"String_Node_Str",primaryCode,isPredictionOn(),mPredicting);
  mExpectingSelectionUpdateBy=SystemClock.uptimeMillis() + MAX_TIME_TO_EXPECT_SELECTION_UPDATE;
  if (!mPredicting && isPredictionOn() && isAlphabet(primaryCode)&& !isCursorTouchingWord()) {
    mPredicting=true;
    mUndoCommitCursorPosition=UNDO_COMMIT_NONE;
    mWord.reset();
    mAutoCorrectOn=mAutoComplete;
  }
  mLastCharacterWasShifted=(getInputView() != null) && getInputView().isShifted();
  final int primaryCodeToOutput;
  if (mShiftKeyState.isActive()) {
    if (key != null) {
      primaryCodeToOutput=key.getCodeAtIndex(multiTapIndex,true);
    }
 else {
      primaryCodeToOutput=Character.toUpperCase(primaryCode);
    }
  }
 else {
    if (getKeyboardSwitcher().isRightToLeftMode()) {
      if (primaryCode == (int)')')       primaryCodeToOutput=(int)'(';
 else       if (primaryCode == (int)'(')       primaryCodeToOutput=(int)')';
 else       primaryCodeToOutput=primaryCode;
    }
 else {
      primaryCodeToOutput=primaryCode;
    }
  }
  if (mPredicting) {
    if (mShiftKeyState.isActive() && mWord.cursorPosition() == 0) {
      mWord.setFirstCharCapitalized(true);
    }
    final InputConnection ic=getCurrentInputConnection();
    mWord.add(primaryCodeToOutput,nearByKeyCodes);
    ChewbaccaOnTheDrums.onKeyTyped(mWord,getApplicationContext());
    if (ic != null) {
      final int cursorPosition;
      if (mWord.cursorPosition() != mWord.length()) {
        cursorPosition=mGlobalCursorPosition + 1;
        ic.beginBatchEdit();
      }
 else {
        cursorPosition=-1;
      }
      ic.setComposingText(mWord.getTypedWord(),1);
      if (cursorPosition > 0) {
        ic.setSelection(cursorPosition,cursorPosition);
        ic.endBatchEdit();
      }
    }
    if (Character.isLetter((char)primaryCodeToOutput)) {
      postUpdateSuggestions();
    }
 else {
      if (mCandidateView != null)       mCandidateView.replaceTypedWord(mWord.getTypedWord());
    }
  }
 else {
    sendKeyChar((char)primaryCodeToOutput);
  }
  TextEntryState.typedCharacter((char)primaryCodeToOutput,false);
  mJustAutoAddedWord=false;
}

Fixed version (ground truth):
private void handleCharacter(final int primaryCode,final Key key,final int multiTapIndex,int[] nearByKeyCodes){
  if (BuildConfig.DEBUG)   Logger.d(TAG,"String_Node_Str",primaryCode,isPredictionOn(),mPredicting);
  mExpectingSelectionUpdateBy=SystemClock.uptimeMillis() + MAX_TIME_TO_EXPECT_SELECTION_UPDATE;
  if (!mPredicting && isPredictionOn() && isAlphabet(primaryCode)&& !isCursorTouchingWord()) {
    mPredicting=true;
    mUndoCommitCursorPosition=UNDO_COMMIT_NONE;
    mWord.reset();
    mAutoCorrectOn=mAutoComplete;
  }
  mLastCharacterWasShifted=(getInputView() != null) && getInputView().isShifted();
  final int primaryCodeToOutput;
  if (mShiftKeyState.isActive()) {
    if (key != null) {
      primaryCodeToOutput=key.getCodeAtIndex(multiTapIndex,true);
    }
 else {
      primaryCodeToOutput=Character.toUpperCase(primaryCode);
    }
  }
 else {
    primaryCodeToOutput=primaryCode;
  }
  if (mPredicting) {
    if (mShiftKeyState.isActive() && mWord.cursorPosition() == 0) {
      mWord.setFirstCharCapitalized(true);
    }
    final InputConnection ic=getCurrentInputConnection();
    mWord.add(primaryCodeToOutput,nearByKeyCodes);
    ChewbaccaOnTheDrums.onKeyTyped(mWord,getApplicationContext());
    if (ic != null) {
      final int cursorPosition;
      if (mWord.cursorPosition() != mWord.length()) {
        cursorPosition=mGlobalCursorPosition + 1;
        ic.beginBatchEdit();
      }
 else {
        cursorPosition=-1;
      }
      ic.setComposingText(mWord.getTypedWord(),1);
      if (cursorPosition > 0) {
        ic.setSelection(cursorPosition,cursorPosition);
        ic.endBatchEdit();
      }
    }
    if (Character.isLetter((char)primaryCodeToOutput)) {
      postUpdateSuggestions();
    }
 else {
      if (mCandidateView != null)       mCandidateView.replaceTypedWord(mWord.getTypedWord());
    }
  }
 else {
    sendKeyChar((char)primaryCodeToOutput);
  }
  TextEntryState.typedCharacter((char)primaryCodeToOutput,false);
  mJustAutoAddedWord=false;
}