Program: 157359
Project: 157359
Buggy source:
public void onFunctionKey(int primaryCode,Key key,int multiTapIndex,int[] nearByKeyCodes,boolean fromUI){
  if (BuildConfig.DEBUG)   Log.d(TAG,"String_Node_Str",primaryCode);
  final InputConnection ic=getCurrentInputConnection();
switch (primaryCode) {
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.SHIFT:
if (fromUI) {
handleShift();
}
 else {
onPress(primaryCode);
onRelease(primaryCode);
}
break;
case KeyCodes.SHIFT_LOCK:
mShiftKeyState.toggleLocked();
handleShift();
break;
case KeyCodes.DELETE_WORD:
if (ic == null) break;
handleBackWord(ic);
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 (fromUI) {
handleControl();
}
 else {
onPress(primaryCode);
onRelease(primaryCode);
}
break;
case KeyCodes.CTRL_LOCK:
mControlKeyState.toggleLocked();
handleControl();
break;
case KeyCodes.ARROW_LEFT:
case KeyCodes.ARROW_RIGHT:
final int keyEventKeyCode=primaryCode == KeyCodes.ARROW_LEFT ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT;
if (!handleSelectionExpending(keyEventKeyCode,ic)) {
sendDownUpKeyEvents(keyEventKeyCode);
}
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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
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(key,mAskPrefs.getDomainText());
break;
case KeyCodes.QUICK_TEXT:
if (mDoNotFlipQuickTextKeyAndPopupFunctionality) {
outputCurrentQuickTextKey(key);
}
 else {
openQuickTextPopup(key);
}
break;
case KeyCodes.QUICK_TEXT_POPUP:
if (mDoNotFlipQuickTextKeyAndPopupFunctionality) {
openQuickTextPopup(key);
}
 else {
outputCurrentQuickTextKey(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_COPY:
case KeyCodes.CLIPBOARD_PASTE:
case KeyCodes.CLIPBOARD_CUT:
handleClipboardOperation(key,primaryCode);
break;
case KeyCodes.CLIPBOARD_SELECT_ALL:
final CharSequence toLeft=ic.getTextBeforeCursor(10240,0);
final CharSequence toRight=ic.getTextAfterCursor(10240,0);
final int leftLength=toLeft == null ? 0 : toLeft.length();
final int rightLength=toRight == null ? 0 : toRight.length();
if (leftLength != 0 || rightLength != 0) {
ic.setSelection(0,leftLength + rightLength);
}
break;
case KeyCodes.CLIPBOARD_SELECT:
mArrowSelectionState=!mArrowSelectionState;
break;
case KeyCodes.CLIPBOARD_PASTE_POPUP:
showAllClipboardEntries(key);
break;
default :
if (BuildConfig.DEBUG) {
throw new RuntimeException("String_Node_Str" + primaryCode);
}
 else {
Log.w(TAG,"String_Node_Str",primaryCode);
}
}
}

Fixed version (ground truth):
public void onFunctionKey(int primaryCode,Key key,int multiTapIndex,int[] nearByKeyCodes,boolean fromUI){
  if (BuildConfig.DEBUG)   Log.d(TAG,"String_Node_Str",primaryCode);
  final InputConnection ic=getCurrentInputConnection();
switch (primaryCode) {
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.SHIFT:
if (fromUI) {
handleShift();
}
 else {
onPress(primaryCode);
onRelease(primaryCode);
}
break;
case KeyCodes.SHIFT_LOCK:
mShiftKeyState.toggleLocked();
handleShift();
break;
case KeyCodes.DELETE_WORD:
if (ic == null) break;
handleBackWord(ic);
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 (fromUI) {
handleControl();
}
 else {
onPress(primaryCode);
onRelease(primaryCode);
}
break;
case KeyCodes.CTRL_LOCK:
mControlKeyState.toggleLocked();
handleControl();
break;
case KeyCodes.ARROW_LEFT:
case KeyCodes.ARROW_RIGHT:
final int keyEventKeyCode=primaryCode == KeyCodes.ARROW_LEFT ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT;
if (!handleSelectionExpending(keyEventKeyCode,ic)) {
sendDownUpKeyEvents(keyEventKeyCode);
}
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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
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);
setKeyboardForView(getCurrentKeyboard());
}
break;
case KeyCodes.DOMAIN:
onText(key,mAskPrefs.getDomainText());
break;
case KeyCodes.QUICK_TEXT:
if (mDoNotFlipQuickTextKeyAndPopupFunctionality) {
outputCurrentQuickTextKey(key);
}
 else {
openQuickTextPopup(key);
}
break;
case KeyCodes.QUICK_TEXT_POPUP:
if (mDoNotFlipQuickTextKeyAndPopupFunctionality) {
openQuickTextPopup(key);
}
 else {
outputCurrentQuickTextKey(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_COPY:
case KeyCodes.CLIPBOARD_PASTE:
case KeyCodes.CLIPBOARD_CUT:
handleClipboardOperation(key,primaryCode);
break;
case KeyCodes.CLIPBOARD_SELECT_ALL:
final CharSequence toLeft=ic.getTextBeforeCursor(10240,0);
final CharSequence toRight=ic.getTextAfterCursor(10240,0);
final int leftLength=toLeft == null ? 0 : toLeft.length();
final int rightLength=toRight == null ? 0 : toRight.length();
if (leftLength != 0 || rightLength != 0) {
ic.setSelection(0,leftLength + rightLength);
}
break;
case KeyCodes.CLIPBOARD_SELECT:
mArrowSelectionState=!mArrowSelectionState;
break;
case KeyCodes.CLIPBOARD_PASTE_POPUP:
showAllClipboardEntries(key);
break;
default :
if (BuildConfig.DEBUG) {
throw new RuntimeException("String_Node_Str" + primaryCode);
}
 else {
Log.w(TAG,"String_Node_Str",primaryCode);
}
}
}