Program: 157432
Project: 157432
Buggy source:
public void onKey(int primaryCode,Key key,int multiTapIndex,int[] nearByKeyCodes,boolean fromUI){
  Log.d(TAG,"String_Node_Str" + primaryCode);
  final InputConnection ic=getCurrentInputConnection();
switch (primaryCode) {
case KeyCodes.ENTER:
case KeyCodes.SPACE:
    handleSeparator(primaryCode);
  if (!mKeyboardSwitcher.isAlphabetMode()) {
    Log.d(TAG,"String_Node_Str");
    if (mAskPrefs.getSwitchKeyboardOnSpace()) {
      Log.d(TAG,"String_Node_Str");
      mKeyboardSwitcher.nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Alphabet);
    }
  }
break;
case KeyCodes.DELETE_WORD:
if (ic == null) break;
handleBackWord(ic);
break;
case KeyCodes.DELETE:
if (ic == null) break;
if (mInputView != null && mInputView.isShifted() && !mInputView.getKeyboard().isShiftLocked() && ((mDistinctMultiTouch && mShiftKeyState.isPressed()) || mAskPrefs.useBackword())) {
handleBackWord(ic);
}
 else {
handleDeleteLastCharacter(false);
}
break;
case KeyCodes.CLEAR_INPUT:
if (ic != null) {
ic.beginBatchEdit();
commitTyped(ic);
ic.deleteSurroundingText(Integer.MAX_VALUE,Integer.MAX_VALUE);
ic.endBatchEdit();
}
break;
case KeyCodes.CTRL:
if ((!mDistinctMultiTouch) || (!fromUI)) handleControl();
break;
case KeyCodes.SHIFT:
if ((!mDistinctMultiTouch) || (!fromUI)) handleShift();
break;
case KeyCodes.ARROW_LEFT:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
break;
case KeyCodes.ARROW_RIGHT:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
break;
case KeyCodes.ARROW_UP:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_UP);
break;
case KeyCodes.ARROW_DOWN:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_DOWN);
break;
case KeyCodes.MOVE_HOME:
if (Workarounds.getApiLevel() >= 11) {
sendDownUpKeyEvents(0x0000007a);
}
 else {
if (ic != null) {
CharSequence textBefore=ic.getTextBeforeCursor(1024,0);
if (!TextUtils.isEmpty(textBefore)) {
int newPosition=textBefore.length() - 1;
while (newPosition > 0) {
char chatAt=textBefore.charAt(newPosition - 1);
if (chatAt == '\n' || chatAt == '\r') {
break;
}
newPosition--;
}
if (newPosition < 0) newPosition=0;
ic.setSelection(newPosition,newPosition);
}
}
}
break;
case KeyCodes.MOVE_END:
if (Workarounds.getApiLevel() >= 11) {
sendDownUpKeyEvents(0x0000007b);
}
 else {
if (ic != null) {
CharSequence textAfter=ic.getTextAfterCursor(1024,0);
if (!TextUtils.isEmpty(textAfter)) {
int newPosition=1;
while (newPosition < textAfter.length()) {
char chatAt=textAfter.charAt(newPosition);
if (chatAt == '\n' || chatAt == '\r') {
break;
}
newPosition++;
}
if (newPosition > textAfter.length()) newPosition=textAfter.length();
try {
CharSequence textBefore=ic.getTextBeforeCursor(Integer.MAX_VALUE,0);
if (!TextUtils.isEmpty(textBefore)) {
newPosition=newPosition + textBefore.length();
}
ic.setSelection(newPosition,newPosition);
}
 catch (Throwable e) {
Log.w(TAG,"String_Node_Str",e);
}
}
}
}
break;
case KeyCodes.VOICE_INPUT:
if (mVoiceRecognitionTrigger.isInstalled()) {
mVoiceRecognitionTrigger.startVoiceRecognition(getCurrentKeyboard().getDefaultDictionaryLocale());
}
 else {
Intent voiceInputNotInstalledIntent=new Intent(getApplicationContext(),VoiceInputNotInstalledActivity.class);
voiceInputNotInstalledIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(voiceInputNotInstalledIntent);
}
break;
case KeyCodes.CANCEL:
if (mOptionsDialog == null || !mOptionsDialog.isShowing()) {
handleClose();
}
break;
case KeyCodes.SETTINGS:
showOptionsMenu();
break;
case KeyCodes.SPLIT_LAYOUT:
case KeyCodes.MERGE_LAYOUT:
case KeyCodes.COMPACT_LAYOUT_TO_RIGHT:
case KeyCodes.COMPACT_LAYOUT_TO_LEFT:
if (getCurrentKeyboard() != null && mInputView != null) {
mKeyboardInCondensedMode=CondenseType.fromKeyCode(primaryCode);
AnyKeyboard currentKeyboard=getCurrentKeyboard();
setKeyboardStuffBeforeSetToView(currentKeyboard);
mInputView.setKeyboard(currentKeyboard);
}
break;
case KeyCodes.DOMAIN:
onText(mAskPrefs.getDomainText());
break;
case KeyCodes.QUICK_TEXT:
if (mFlipQuickTextKeyAndPopupFunctionality) {
openQuickTextPopup(key);
}
 else {
outputCurrentQuickTextKey();
}
break;
case KeyCodes.QUICK_TEXT_POPUP:
if (mFlipQuickTextKeyAndPopupFunctionality) {
outputCurrentQuickTextKey();
}
 else {
openQuickTextPopup(key);
}
break;
case KeyCodes.MODE_SYMOBLS:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Symbols);
break;
case KeyCodes.MODE_ALPHABET:
if (mKeyboardSwitcher.shouldPopupForLanguageSwitch()) {
showLanguageSelectionDialog();
}
 else nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Alphabet);
break;
case KeyCodes.UTILITY_KEYBOARD:
mInputView.openUtilityKeyboard();
break;
case KeyCodes.MODE_ALPHABET_POPUP:
showLanguageSelectionDialog();
break;
case KeyCodes.ALT:
nextAlterKeyboard(getCurrentInputEditorInfo());
break;
case KeyCodes.KEYBOARD_CYCLE:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Any);
break;
case KeyCodes.KEYBOARD_REVERSE_CYCLE:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.PreviousAny);
break;
case KeyCodes.KEYBOARD_CYCLE_INSIDE_MODE:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.AnyInsideMode);
break;
case KeyCodes.KEYBOARD_MODE_CHANGE:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.OtherMode);
break;
case KeyCodes.CLIPBOARD:
Clipboard cp=AnyApplication.getFrankenRobot().embody(new Clipboard.ClipboardDiagram(getApplicationContext()));
CharSequence clipboardText=cp.getText();
if (!TextUtils.isEmpty(clipboardText)) {
onText(clipboardText);
}
break;
case KeyCodes.TAB:
sendTab();
break;
case KeyCodes.ESCAPE:
sendEscape();
break;
default :
if (mKeyboardSwitcher.isRightToLeftMode()) {
if (primaryCode == (int)')') primaryCode=(int)'(';
 else if (primaryCode == (int)'(') primaryCode=(int)')';
}
if (isWordSeparator(primaryCode)) {
handleSeparator(primaryCode);
}
 else {
if (mControlKeyState.isActive() && primaryCode >= 32 && primaryCode < 127) {
int controlCode=primaryCode & 31;
Log.d(TAG,"String_Node_Str",primaryCode,controlCode);
if (controlCode == 9) {
sendTab();
}
 else {
ic.commitText(Character.toString((char)controlCode),1);
}
}
 else {
handleCharacter(primaryCode,key,multiTapIndex,nearByKeyCodes);
}
mJustAddedAutoSpace=false;
}
break;
}
}

Fixed version (ground truth):
public void onKey(int primaryCode,Key key,int multiTapIndex,int[] nearByKeyCodes,boolean fromUI){
  Log.d(TAG,"String_Node_Str" + primaryCode);
  final InputConnection ic=getCurrentInputConnection();
switch (primaryCode) {
case KeyCodes.ENTER:
case KeyCodes.SPACE:
    handleSeparator(primaryCode);
  if (!mKeyboardSwitcher.isAlphabetMode()) {
    Log.d(TAG,"String_Node_Str");
    if (mAskPrefs.getSwitchKeyboardOnSpace()) {
      Log.d(TAG,"String_Node_Str");
      mKeyboardSwitcher.nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Alphabet);
    }
  }
break;
case KeyCodes.DELETE_WORD:
if (ic == null) break;
handleBackWord(ic);
break;
case KeyCodes.DELETE:
if (ic == null) break;
if (mInputView != null && mInputView.isShifted() && !mInputView.getKeyboard().isShiftLocked() && ((mDistinctMultiTouch && mShiftKeyState.isPressed()) || mAskPrefs.useBackword())) {
handleBackWord(ic);
}
 else {
handleDeleteLastCharacter(false);
}
break;
case KeyCodes.CLEAR_INPUT:
if (ic != null) {
ic.beginBatchEdit();
commitTyped(ic);
ic.deleteSurroundingText(Integer.MAX_VALUE,Integer.MAX_VALUE);
ic.endBatchEdit();
}
break;
case KeyCodes.CTRL:
if ((!mDistinctMultiTouch) || (!fromUI)) handleControl();
break;
case KeyCodes.SHIFT:
if ((!mDistinctMultiTouch) || (!fromUI)) handleShift();
break;
case KeyCodes.ARROW_LEFT:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
break;
case KeyCodes.ARROW_RIGHT:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
break;
case KeyCodes.ARROW_UP:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_UP);
break;
case KeyCodes.ARROW_DOWN:
sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_DOWN);
break;
case KeyCodes.MOVE_HOME:
if (Workarounds.getApiLevel() >= 11) {
sendDownUpKeyEvents(0x0000007a);
}
 else {
if (ic != null) {
CharSequence textBefore=ic.getTextBeforeCursor(1024,0);
if (!TextUtils.isEmpty(textBefore)) {
int newPosition=textBefore.length() - 1;
while (newPosition > 0) {
char chatAt=textBefore.charAt(newPosition - 1);
if (chatAt == '\n' || chatAt == '\r') {
break;
}
newPosition--;
}
if (newPosition < 0) newPosition=0;
ic.setSelection(newPosition,newPosition);
}
}
}
break;
case KeyCodes.MOVE_END:
if (Workarounds.getApiLevel() >= 11) {
sendDownUpKeyEvents(0x0000007b);
}
 else {
if (ic != null) {
CharSequence textAfter=ic.getTextAfterCursor(1024,0);
if (!TextUtils.isEmpty(textAfter)) {
int newPosition=1;
while (newPosition < textAfter.length()) {
char chatAt=textAfter.charAt(newPosition);
if (chatAt == '\n' || chatAt == '\r') {
break;
}
newPosition++;
}
if (newPosition > textAfter.length()) newPosition=textAfter.length();
try {
CharSequence textBefore=ic.getTextBeforeCursor(Integer.MAX_VALUE,0);
if (!TextUtils.isEmpty(textBefore)) {
newPosition=newPosition + textBefore.length();
}
ic.setSelection(newPosition,newPosition);
}
 catch (Throwable e) {
Log.w(TAG,"String_Node_Str",e);
}
}
}
}
break;
case KeyCodes.VOICE_INPUT:
if (mVoiceRecognitionTrigger.isInstalled()) {
mVoiceRecognitionTrigger.startVoiceRecognition(getCurrentKeyboard().getDefaultDictionaryLocale());
}
 else {
Intent voiceInputNotInstalledIntent=new Intent(getApplicationContext(),VoiceInputNotInstalledActivity.class);
voiceInputNotInstalledIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(voiceInputNotInstalledIntent);
}
break;
case KeyCodes.CANCEL:
if (mOptionsDialog == null || !mOptionsDialog.isShowing()) {
handleClose();
}
break;
case KeyCodes.SETTINGS:
showOptionsMenu();
break;
case KeyCodes.SPLIT_LAYOUT:
case KeyCodes.MERGE_LAYOUT:
case KeyCodes.COMPACT_LAYOUT_TO_RIGHT:
case KeyCodes.COMPACT_LAYOUT_TO_LEFT:
if (getCurrentKeyboard() != null && mInputView != null) {
mKeyboardInCondensedMode=CondenseType.fromKeyCode(primaryCode);
AnyKeyboard currentKeyboard=getCurrentKeyboard();
setKeyboardStuffBeforeSetToView(currentKeyboard);
mInputView.setKeyboard(currentKeyboard);
}
break;
case KeyCodes.DOMAIN:
onText(mAskPrefs.getDomainText());
break;
case KeyCodes.QUICK_TEXT:
if (mDoNotFlipQuickTextKeyAndPopupFunctionality) {
outputCurrentQuickTextKey();
}
 else {
openQuickTextPopup(key);
}
break;
case KeyCodes.QUICK_TEXT_POPUP:
if (mDoNotFlipQuickTextKeyAndPopupFunctionality) {
openQuickTextPopup(key);
}
 else {
outputCurrentQuickTextKey();
}
break;
case KeyCodes.MODE_SYMOBLS:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Symbols);
break;
case KeyCodes.MODE_ALPHABET:
if (mKeyboardSwitcher.shouldPopupForLanguageSwitch()) {
showLanguageSelectionDialog();
}
 else nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Alphabet);
break;
case KeyCodes.UTILITY_KEYBOARD:
mInputView.openUtilityKeyboard();
break;
case KeyCodes.MODE_ALPHABET_POPUP:
showLanguageSelectionDialog();
break;
case KeyCodes.ALT:
nextAlterKeyboard(getCurrentInputEditorInfo());
break;
case KeyCodes.KEYBOARD_CYCLE:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Any);
break;
case KeyCodes.KEYBOARD_REVERSE_CYCLE:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.PreviousAny);
break;
case KeyCodes.KEYBOARD_CYCLE_INSIDE_MODE:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.AnyInsideMode);
break;
case KeyCodes.KEYBOARD_MODE_CHANGE:
nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.OtherMode);
break;
case KeyCodes.CLIPBOARD:
Clipboard cp=AnyApplication.getFrankenRobot().embody(new Clipboard.ClipboardDiagram(getApplicationContext()));
CharSequence clipboardText=cp.getText();
if (!TextUtils.isEmpty(clipboardText)) {
onText(clipboardText);
}
break;
case KeyCodes.TAB:
sendTab();
break;
case KeyCodes.ESCAPE:
sendEscape();
break;
default :
if (mKeyboardSwitcher.isRightToLeftMode()) {
if (primaryCode == (int)')') primaryCode=(int)'(';
 else if (primaryCode == (int)'(') primaryCode=(int)')';
}
if (isWordSeparator(primaryCode)) {
handleSeparator(primaryCode);
}
 else {
if (mControlKeyState.isActive() && primaryCode >= 32 && primaryCode < 127) {
int controlCode=primaryCode & 31;
Log.d(TAG,"String_Node_Str",primaryCode,controlCode);
if (controlCode == 9) {
sendTab();
}
 else {
ic.commitText(Character.toString((char)controlCode),1);
}
}
 else {
handleCharacter(primaryCode,key,multiTapIndex,nearByKeyCodes);
}
mJustAddedAutoSpace=false;
}
break;
}
}