Program: 157519
Project: 157519
Buggy source:
/** 
 * Get Key from primary code. on onKey event, it only gets primary key. So, to access Key of it, we need to find Key which contains it.
 */
public void onKey(int primaryCode,Key key,int multiTapIndex,int[] nearByKeyCodes,boolean fromUI){
  if (DEBUG) {
    Log.d(TAG,"String_Node_Str" + primaryCode);
  }
  final InputConnection ic=getCurrentInputConnection();
switch (primaryCode) {
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.isMomentary()) || mConfig.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.SHIFT:
if ((!mDistinctMultiTouch) || !fromUI) handleShift(false);
break;
case KeyCodes.CTRL:
if ((!mDistinctMultiTouch) || !fromUI) handleControl(false);
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();
CharSequence textBefore=ic.getTextBeforeCursor(Integer.MAX_VALUE,0);
ic.setSelection(newPosition + textBefore.length(),newPosition + textBefore.length());
}
}
}
break;
case KeyCodes.VOICE_INPUT:
if (mVoiceRecognitionTrigger != null) mVoiceRecognitionTrigger.startVoiceRecognition(getCurrentKeyboard().getDefaultDictionaryLocale());
break;
case KeyCodes.CANCEL:
if (mOptionsDialog == null || !mOptionsDialog.isShowing()) {
handleClose();
}
break;
case KeyCodes.SETTINGS:
showOptionsMenu();
break;
case KeyCodes.SPLIT_LAYOUT:
case KeyCodes.MERGE_LAYOUT:
if (getCurrentKeyboard() != null && mInputView != null) {
mKeyboardInCondensedMode=KeyCodes.SPLIT_LAYOUT == primaryCode;
AnyKeyboard currentKeyboard=getCurrentKeyboard();
setKeyboardStuffBeforeSetToView(currentKeyboard);
mInputView.setKeyboard(currentKeyboard);
}
break;
case KeyCodes.DOMAIN:
onText(mConfig.getDomainText());
break;
case KeyCodes.QUICK_TEXT:
QuickTextKey quickTextKey=QuickTextKeyFactory.getCurrentQuickTextKey(this);
if (mSmileyOnShortPress) {
if (TextUtils.isEmpty(mOverrideQuickTextText)) onText(quickTextKey.getKeyOutputText());
 else onText(mOverrideQuickTextText);
}
 else {
if (quickTextKey.isPopupKeyboardUsed()) {
showQuickTextKeyPopupKeyboard(quickTextKey);
}
 else {
showQuickTextKeyPopupList(quickTextKey);
}
}
break;
case KeyCodes.QUICK_TEXT_POPUP:
quickTextKey=QuickTextKeyFactory.getCurrentQuickTextKey(this);
if (quickTextKey.getId().equals(SMILEY_PLUGIN_ID) && !mSmileyOnShortPress) {
if (TextUtils.isEmpty(mOverrideQuickTextText)) onText(quickTextKey.getKeyOutputText());
 else onText(mOverrideQuickTextText);
}
 else {
if (quickTextKey.isPopupKeyboardUsed()) {
showQuickTextKeyPopupKeyboard(quickTextKey);
}
 else {
showQuickTextKeyPopupList(quickTextKey);
}
}
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.getDeviceSpecific().getClipboard(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 (mInputView != null && mInputView.isControl() && primaryCode >= 32 && primaryCode < 127) {
int controlCode=primaryCode & 31;
if (AnyApplication.DEBUG) Log.d(TAG,"String_Node_Str" + primaryCode + "String_Node_Str"+ controlCode);
if (controlCode == 9) {
sendTab();
}
 else {
ic.commitText(Character.toString((char)controlCode),1);
}
}
 else {
handleCharacter(primaryCode,key,multiTapIndex,nearByKeyCodes);
}
mJustAddedAutoSpace=false;
}
if (mKeyboardSwitcher.isKeyRequireSwitchToAlphabet(primaryCode)) {
mKeyboardSwitcher.nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Alphabet);
}
break;
}
}

Fixed version (ground truth):
public void onKey(int primaryCode,Key key,int multiTapIndex,int[] nearByKeyCodes,boolean fromUI){
  if (DEBUG) {
    Log.d(TAG,"String_Node_Str" + primaryCode);
  }
  final InputConnection ic=getCurrentInputConnection();
switch (primaryCode) {
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.isMomentary()) || mConfig.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.SHIFT:
if ((!mDistinctMultiTouch) || !fromUI) handleShift(false);
break;
case KeyCodes.CTRL:
if ((!mDistinctMultiTouch) || !fromUI) handleControl(false);
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();
CharSequence textBefore=ic.getTextBeforeCursor(Integer.MAX_VALUE,0);
ic.setSelection(newPosition + textBefore.length(),newPosition + textBefore.length());
}
}
}
break;
case KeyCodes.VOICE_INPUT:
if (mVoiceRecognitionTrigger != null) mVoiceRecognitionTrigger.startVoiceRecognition(getCurrentKeyboard().getDefaultDictionaryLocale());
break;
case KeyCodes.CANCEL:
if (mOptionsDialog == null || !mOptionsDialog.isShowing()) {
handleClose();
}
break;
case KeyCodes.SETTINGS:
showOptionsMenu();
break;
case KeyCodes.SPLIT_LAYOUT:
case KeyCodes.MERGE_LAYOUT:
if (getCurrentKeyboard() != null && mInputView != null) {
mKeyboardInCondensedMode=KeyCodes.SPLIT_LAYOUT == primaryCode;
AnyKeyboard currentKeyboard=getCurrentKeyboard();
setKeyboardStuffBeforeSetToView(currentKeyboard);
mInputView.setKeyboard(currentKeyboard);
}
break;
case KeyCodes.DOMAIN:
onText(mConfig.getDomainText());
break;
case KeyCodes.QUICK_TEXT:
QuickTextKey quickTextKey=QuickTextKeyFactory.getCurrentQuickTextKey(this);
if (mSmileyOnShortPress) {
if (TextUtils.isEmpty(mOverrideQuickTextText)) onText(quickTextKey.getKeyOutputText());
 else onText(mOverrideQuickTextText);
}
 else {
if (quickTextKey.isPopupKeyboardUsed()) {
showQuickTextKeyPopupKeyboard(quickTextKey);
}
 else {
showQuickTextKeyPopupList(quickTextKey);
}
}
break;
case KeyCodes.QUICK_TEXT_POPUP:
quickTextKey=QuickTextKeyFactory.getCurrentQuickTextKey(this);
if (quickTextKey.getId().equals(SMILEY_PLUGIN_ID) && !mSmileyOnShortPress) {
if (TextUtils.isEmpty(mOverrideQuickTextText)) onText(quickTextKey.getKeyOutputText());
 else onText(mOverrideQuickTextText);
}
 else {
if (quickTextKey.isPopupKeyboardUsed()) {
showQuickTextKeyPopupKeyboard(quickTextKey);
}
 else {
showQuickTextKeyPopupList(quickTextKey);
}
}
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.getDeviceSpecific().getClipboard(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 (mInputView != null && mInputView.isControl() && primaryCode >= 32 && primaryCode < 127) {
int controlCode=primaryCode & 31;
if (AnyApplication.DEBUG) Log.d(TAG,"String_Node_Str" + primaryCode + "String_Node_Str"+ controlCode);
if (controlCode == 9) {
sendTab();
}
 else {
ic.commitText(Character.toString((char)controlCode),1);
}
}
 else {
handleCharacter(primaryCode,key,multiTapIndex,nearByKeyCodes);
}
mJustAddedAutoSpace=false;
}
if (mKeyboardSwitcher.isKeyRequireSwitchToAlphabet(primaryCode)) {
mKeyboardSwitcher.nextKeyboard(getCurrentInputEditorInfo(),NextKeyboardType.Alphabet);
}
break;
}
}