nus-yam/ex-repair huggingface dataset:
Program: 88336
Project: 88336
Buggy source:
public static void logOnAutoSuggestionCanceled(){
  if (sLogEnabled) {
    sLatinImeLogger.mAutoCancelledCount++;
    if (sLastAutoSuggestBefore != null && sLastAutoSuggestAfter != null) {
      String[] strings=new String[]{sLastAutoSuggestBefore,sLastAutoSuggestAfter,sLastAutoSuggestSeparator};
      sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTIONCANCELLED,strings);
    }
synchronized (LatinImeLogger.class) {
      sLastAutoSuggestBefore="String_Node_Str";
      sLastAutoSuggestAfter="String_Node_Str";
      sLastAutoSuggestSeparator="String_Node_Str";
    }
  }
}

Fixed version (ground truth):
public static void logOnAutoSuggestionCanceled(){
  if (sLogEnabled) {
    sLatinImeLogger.mAutoCancelledCountPerDic[sLastAutoSuggestDicTypeId]++;
    if (sLastAutoSuggestBefore != null && sLastAutoSuggestAfter != null) {
      String[] strings=new String[]{sLastAutoSuggestBefore,sLastAutoSuggestAfter,sLastAutoSuggestSeparator};
      sLatinImeLogger.sendLogToDropBox(ID_AUTOSUGGESTIONCANCELLED,strings);
    }
synchronized (LatinImeLogger.class) {
      sLastAutoSuggestBefore="String_Node_Str";
      sLastAutoSuggestAfter="String_Node_Str";
      sLastAutoSuggestSeparator="String_Node_Str";
    }
  }
}
Program: 88337
Project: 88337
Buggy source:
private void initInternal(Context context){
  mContext=context;
  mDropBox=(DropBoxManager)mContext.getSystemService(Context.DROPBOX_SERVICE);
  mLastTimeSend=System.currentTimeMillis();
  mLastTimeActive=mLastTimeSend;
  mLastTimeCountEntry=mLastTimeSend;
  mDeleteCount=0;
  mInputCount=0;
  mWordCount=0;
  mActualCharCount=0;
  Arrays.fill(mAutoSuggestCountPerDic,0);
  Arrays.fill(mManualSuggestCountPerDic,0);
  mAutoCancelledCount=0;
  mLogBuffer=new ArrayList<LogEntry>();
  mPrivacyLogBuffer=new ArrayList<LogEntry>();
  mRingCharBuffer=new RingCharBuffer(context);
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context);
  sLogEnabled=prefs.getBoolean(PREF_ENABLE_LOG,DEFAULT_LOG_ENABLED);
  mThemeId=prefs.getString(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT,KeyboardSwitcher.DEFAULT_LAYOUT_ID);
  sLOGPRINT=prefs.getBoolean(PREF_DEBUG_MODE,sLOGPRINT);
  sDBG=sLOGPRINT;
  prefs.registerOnSharedPreferenceChangeListener(this);
}

Fixed version (ground truth):
private void initInternal(Context context){
  mContext=context;
  mDropBox=(DropBoxManager)mContext.getSystemService(Context.DROPBOX_SERVICE);
  mLastTimeSend=System.currentTimeMillis();
  mLastTimeActive=mLastTimeSend;
  mLastTimeCountEntry=mLastTimeSend;
  mDeleteCount=0;
  mInputCount=0;
  mWordCount=0;
  mActualCharCount=0;
  Arrays.fill(mAutoSuggestCountPerDic,0);
  Arrays.fill(mManualSuggestCountPerDic,0);
  Arrays.fill(mAutoCancelledCountPerDic,0);
  mLogBuffer=new ArrayList<LogEntry>();
  mPrivacyLogBuffer=new ArrayList<LogEntry>();
  mRingCharBuffer=new RingCharBuffer(context);
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context);
  sLogEnabled=prefs.getBoolean(PREF_ENABLE_LOG,DEFAULT_LOG_ENABLED);
  mThemeId=prefs.getString(KeyboardSwitcher.PREF_KEYBOARD_LAYOUT,KeyboardSwitcher.DEFAULT_LAYOUT_ID);
  sLOGPRINT=prefs.getBoolean(PREF_DEBUG_MODE,sLOGPRINT);
  sDBG=sLOGPRINT;
  prefs.registerOnSharedPreferenceChangeListener(this);
}
Program: 88338
Project: 88338
Buggy source:
private void addSuggestionCountEntry(long time){
  if (sLOGPRINT) {
    Log.d(TAG,"String_Node_Str");
  }
  String[] s=new String[mAutoSuggestCountPerDic.length];
  for (int i=0; i < s.length; ++i) {
    s[i]=String.valueOf(mAutoSuggestCountPerDic[i]);
  }
  mLogBuffer.add(new LogEntry(time,ID_AUTOSUGGESTIONCOUNT,s));
  mLogBuffer.add(new LogEntry(time,ID_AUTOSUGGESTIONCANCELLEDCOUNT,new String[]{String.valueOf(mAutoCancelledCount)}));
  s=new String[mManualSuggestCountPerDic.length];
  for (int i=0; i < s.length; ++i) {
    s[i]=String.valueOf(mManualSuggestCountPerDic[i]);
  }
  mLogBuffer.add(new LogEntry(time,ID_MANUALSUGGESTIONCOUNT,s));
  Arrays.fill(mAutoSuggestCountPerDic,0);
  Arrays.fill(mManualSuggestCountPerDic,0);
  mAutoCancelledCount=0;
}

Fixed version (ground truth):
private void addSuggestionCountEntry(long time){
  if (sLOGPRINT) {
    Log.d(TAG,"String_Node_Str");
  }
  String[] s=new String[mAutoSuggestCountPerDic.length];
  for (int i=0; i < s.length; ++i) {
    s[i]=String.valueOf(mAutoSuggestCountPerDic[i]);
  }
  mLogBuffer.add(new LogEntry(time,ID_AUTOSUGGESTIONCOUNT,s));
  s=new String[mAutoCancelledCountPerDic.length];
  for (int i=0; i < s.length; ++i) {
    s[i]=String.valueOf(mAutoCancelledCountPerDic[i]);
  }
  mLogBuffer.add(new LogEntry(time,ID_AUTOSUGGESTIONCANCELLEDCOUNT,s));
  s=new String[mManualSuggestCountPerDic.length];
  for (int i=0; i < s.length; ++i) {
    s[i]=String.valueOf(mManualSuggestCountPerDic[i]);
  }
  mLogBuffer.add(new LogEntry(time,ID_MANUALSUGGESTIONCOUNT,s));
  Arrays.fill(mAutoSuggestCountPerDic,0);
  Arrays.fill(mManualSuggestCountPerDic,0);
  Arrays.fill(mAutoCancelledCountPerDic,0);
}
Program: 88339
Project: 88339
Buggy source:
public static void logOnManualSuggestion(String before,String after,int position,List<CharSequence> suggestions){
  if (sLogEnabled) {
    if (before.length() == 0 && after.length() == 1) {
      sLatinImeLogger.sendLogToDropBox(ID_MANUALSUGGESTION,new String[]{before,after,String.valueOf(position),"String_Node_Str"});
    }
 else     if (!sSuggestDicMap.containsKey(after)) {
      if (sDBG) {
        Log.e(TAG,"String_Node_Str");
      }
    }
 else {
      int dicTypeId=sSuggestDicMap.get(after);
      sLatinImeLogger.mManualSuggestCountPerDic[dicTypeId]++;
      if (dicTypeId != Suggest.DIC_MAIN) {
        if (sDBG) {
          Log.d(TAG,"String_Node_Str");
        }
      }
 else {
        if (before.equals(after)) {
          before="String_Node_Str";
          after="String_Node_Str";
        }
        String[] strings=new String[3 + suggestions.size()];
        strings[0]=before;
        strings[1]=after;
        strings[2]=String.valueOf(position);
        for (int i=0; i < suggestions.size(); ++i) {
          String s=suggestions.get(i).toString();
          strings[i + 3]=sSuggestDicMap.containsKey(s) ? s : "String_Node_Str";
        }
        sLatinImeLogger.sendLogToDropBox(ID_MANUALSUGGESTION,strings);
      }
    }
    sSuggestDicMap.clear();
  }
}

Fixed version (ground truth):
public static void logOnManualSuggestion(String before,String after,int position,List<CharSequence> suggestions){
  if (sLogEnabled) {
    if (before.length() == 0 && after.length() == 1) {
      sLatinImeLogger.sendLogToDropBox(ID_MANUALSUGGESTION,new String[]{before,after,String.valueOf(position),"String_Node_Str"});
    }
 else     if (!sSuggestDicMap.containsKey(after)) {
      if (sDBG) {
        Log.e(TAG,"String_Node_Str");
      }
    }
 else {
      int dicTypeId=sSuggestDicMap.get(after);
      sLatinImeLogger.mManualSuggestCountPerDic[dicTypeId]++;
      if (dicTypeId != Suggest.DIC_MAIN) {
        if (sDBG) {
          Log.d(TAG,"String_Node_Str");
        }
        before="String_Node_Str";
        after="String_Node_Str";
      }
{
        if (before.equals(after)) {
          before="String_Node_Str";
          after="String_Node_Str";
        }
        String[] strings=new String[3 + suggestions.size()];
        strings[0]=before;
        strings[1]=after;
        strings[2]=String.valueOf(position);
        for (int i=0; i < suggestions.size(); ++i) {
          String s=suggestions.get(i).toString();
          strings[i + 3]=sSuggestDicMap.containsKey(s) ? s : "String_Node_Str";
        }
        sLatinImeLogger.sendLogToDropBox(ID_MANUALSUGGESTION,strings);
      }
    }
    sSuggestDicMap.clear();
  }
}
Program: 88340
Project: 88340
Buggy source:
void setKeyboardMode(int mode,int imeOptions,boolean enableVoice,boolean isSymbols){
  if (mInputView == null)   return;
  mMode=mode;
  mImeOptions=imeOptions;
  if (enableVoice != mHasVoice) {
    setVoiceMode(mHasVoice,mVoiceOnPrimary);
  }
  mIsSymbols=isSymbols;
  mInputView.setPreviewEnabled(true);
  KeyboardId id=getKeyboardId(mode,imeOptions,isSymbols);
  LatinKeyboard keyboard=null;
  try {
    keyboard=getKeyboard(id);
  }
 catch (  RuntimeException e) {
    LatinImeLogger.logOnException(mode + "String_Node_Str" + imeOptions+ "String_Node_Str"+ isSymbols,e);
  }
  if (mode == MODE_PHONE) {
    mInputView.setPhoneKeyboard(keyboard);
    mInputView.setPreviewEnabled(false);
  }
  mCurrentId=id;
  mInputView.setKeyboard(keyboard);
  keyboard.setShifted(false);
  keyboard.setShiftLocked(keyboard.isShiftLocked());
  keyboard.setImeOptions(mContext.getResources(),mMode,imeOptions);
  keyboard.setBlackFlag(isBlackSym());
}

Fixed version (ground truth):
void setKeyboardMode(int mode,int imeOptions,boolean enableVoice,boolean isSymbols){
  if (mInputView == null)   return;
  mMode=mode;
  mImeOptions=imeOptions;
  if (enableVoice != mHasVoice) {
    setVoiceMode(mHasVoice,mVoiceOnPrimary);
  }
  mIsSymbols=isSymbols;
  mInputView.setPreviewEnabled(true);
  KeyboardId id=getKeyboardId(mode,imeOptions,isSymbols);
  LatinKeyboard keyboard=null;
  keyboard=getKeyboard(id);
  if (mode == MODE_PHONE) {
    mInputView.setPhoneKeyboard(keyboard);
    mInputView.setPreviewEnabled(false);
  }
  mCurrentId=id;
  mInputView.setKeyboard(keyboard);
  keyboard.setShifted(false);
  keyboard.setShiftLocked(keyboard.isShiftLocked());
  keyboard.setImeOptions(mContext.getResources(),mMode,imeOptions);
  keyboard.setBlackFlag(isBlackSym());
}
Program: 88341
Project: 88341
Buggy source:
@Override public void onCreate(){
  super.onCreate();
  mResources=getResources();
  final Configuration conf=mResources.getConfiguration();
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  mLanguageSwitcher=new LanguageSwitcher(this);
  mLanguageSwitcher.loadLocales(prefs);
  mKeyboardSwitcher=new KeyboardSwitcher(this,this);
  mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
  mSystemLocale=conf.locale.toString();
  mLanguageSwitcher.setSystemLocale(conf.locale);
  String inputLanguage=mLanguageSwitcher.getInputLanguage();
  if (inputLanguage == null) {
    inputLanguage=conf.locale.toString();
  }
  initSuggest(inputLanguage);
  mOrientation=conf.orientation;
  initSuggestPuncList();
  IntentFilter filter=new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
  registerReceiver(mReceiver,filter);
  if (VOICE_INSTALLED) {
    mVoiceInput=new VoiceInput(this,this);
    mHints=new Hints(this,new Hints.Display(){
      public void showHint(      int viewResource){
        LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(viewResource,null);
        setCandidatesView(view);
        setCandidatesViewShown(true);
        mIsShowingHint=true;
      }
    }
);
  }
  prefs.registerOnSharedPreferenceChangeListener(this);
  LatinImeLogger.init(this);
}

Fixed version (ground truth):
@Override public void onCreate(){
  LatinImeLogger.init(this);
  super.onCreate();
  mResources=getResources();
  final Configuration conf=mResources.getConfiguration();
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  mLanguageSwitcher=new LanguageSwitcher(this);
  mLanguageSwitcher.loadLocales(prefs);
  mKeyboardSwitcher=new KeyboardSwitcher(this,this);
  mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
  mSystemLocale=conf.locale.toString();
  mLanguageSwitcher.setSystemLocale(conf.locale);
  String inputLanguage=mLanguageSwitcher.getInputLanguage();
  if (inputLanguage == null) {
    inputLanguage=conf.locale.toString();
  }
  initSuggest(inputLanguage);
  mOrientation=conf.orientation;
  initSuggestPuncList();
  IntentFilter filter=new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
  registerReceiver(mReceiver,filter);
  if (VOICE_INSTALLED) {
    mVoiceInput=new VoiceInput(this,this);
    mHints=new Hints(this,new Hints.Display(){
      public void showHint(      int viewResource){
        LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(viewResource,null);
        setCandidatesView(view);
        setCandidatesViewShown(true);
        mIsShowingHint=true;
      }
    }
);
  }
  prefs.registerOnSharedPreferenceChangeListener(this);
}
Program: 88342
Project: 88342
Buggy source:
public static void logOnException(String metaData,RuntimeException e){
  if (sLogEnabled) {
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    PrintStream ps=new PrintStream(baos);
    e.printStackTrace(ps);
    String exceptionString=new String(baos.toByteArray());
    sLatinImeLogger.sendLogToDropBox(ID_EXCEPTION,new String[]{metaData,exceptionString});
    Log.e(TAG,"String_Node_Str" + exceptionString);
    if (SUPPRESS_EXCEPTION) {
      sLatinImeLogger.commitInternalAndStopSelf();
    }
 else {
      sLatinImeLogger.commitInternal();
      throw e;
    }
  }
}

Fixed version (ground truth):
public static void logOnException(String metaData,RuntimeException e){
  if (sLogEnabled) {
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    PrintStream ps=new PrintStream(baos);
    e.printStackTrace(ps);
    String exceptionString=new String(baos.toByteArray(),0,Math.min(EXCEPTION_MAX_LENGTH,baos.size()));
    sLatinImeLogger.sendLogToDropBox(ID_EXCEPTION,new String[]{metaData,exceptionString});
    if (DBG) {
      Log.e(TAG,"String_Node_Str" + new String(baos.toByteArray()));
    }
    if (SUPPRESS_EXCEPTION) {
      sLatinImeLogger.commitInternalAndStopSelf();
    }
 else {
      sLatinImeLogger.commitInternal();
      throw e;
    }
  }
}
Program: 88343
Project: 88343
Buggy source:
private void commitInternalAndStopSelf(){
  Log.e(TAG,"String_Node_Str");
  commitInternal();
  LatinIME ime=((LatinIME)mContext);
  ime.hideWindow();
  ime.stopSelf();
}

Fixed version (ground truth):
private void commitInternalAndStopSelf(){
  if (DBG) {
    Log.e(TAG,"String_Node_Str");
  }
  commitInternal();
  LatinIME ime=((LatinIME)mContext);
  ime.hideWindow();
  ime.stopSelf();
}
Program: 88344
Project: 88344
Buggy source:
public void scrollNext(){
  int i=0;
  int scrollX=getScrollX();
  int targetX=scrollX;
  final int count=mSuggestions.size();
  int rightEdge=scrollX + getWidth();
  while (i < count) {
    if (mWordX[i] <= rightEdge && mWordX[i] + mWordWidth[i] >= rightEdge) {
      targetX=Math.min(mWordX[i],mTotalWidth - getWidth());
      break;
    }
    i++;
  }
  updateScrollPosition(targetX);
}

Fixed version (ground truth):
public void scrollNext(){
  int i=0;
  int scrollX=getScrollX();
  int targetX=scrollX;
  final int count=Math.min(mSuggestions.size(),MAX_SUGGESTIONS);
  int rightEdge=scrollX + getWidth();
  while (i < count) {
    if (mWordX[i] <= rightEdge && mWordX[i] + mWordWidth[i] >= rightEdge) {
      targetX=Math.min(mWordX[i],mTotalWidth - getWidth());
      break;
    }
    i++;
  }
  updateScrollPosition(targetX);
}
Program: 88345
Project: 88345
Buggy source:
public void scrollPrev(){
  int i=0;
  final int count=mSuggestions.size();
  int firstItem=0;
  while (i < count) {
    if (mWordX[i] < getScrollX() && mWordX[i] + mWordWidth[i] >= getScrollX() - 1) {
      firstItem=i;
      break;
    }
    i++;
  }
  int leftEdge=mWordX[firstItem] + mWordWidth[firstItem] - getWidth();
  if (leftEdge < 0)   leftEdge=0;
  updateScrollPosition(leftEdge);
}

Fixed version (ground truth):
public void scrollPrev(){
  int i=0;
  final int count=Math.min(mSuggestions.size(),MAX_SUGGESTIONS);
  int firstItem=0;
  while (i < count) {
    if (mWordX[i] < getScrollX() && mWordX[i] + mWordWidth[i] >= getScrollX() - 1) {
      firstItem=i;
      break;
    }
    i++;
  }
  int leftEdge=mWordX[firstItem] + mWordWidth[firstItem] - getWidth();
  if (leftEdge < 0)   leftEdge=0;
  updateScrollPosition(leftEdge);
}
Program: 88347
Project: 88347
Buggy source:
public void scrollNext(){
  int i=0;
  int scrollX=getScrollX();
  int targetX=scrollX;
  final int count=mSuggestions.size();
  int rightEdge=scrollX + getWidth();
  while (i < count) {
    if (mWordX[i] <= rightEdge && mWordX[i] + mWordWidth[i] >= rightEdge) {
      targetX=Math.min(mWordX[i],mTotalWidth - getWidth());
      break;
    }
    i++;
  }
  updateScrollPosition(targetX);
}

Fixed version (ground truth):
public void scrollNext(){
  int i=0;
  int scrollX=getScrollX();
  int targetX=scrollX;
  final int count=Math.min(mSuggestions.size(),MAX_SUGGESTIONS);
  int rightEdge=scrollX + getWidth();
  while (i < count) {
    if (mWordX[i] <= rightEdge && mWordX[i] + mWordWidth[i] >= rightEdge) {
      targetX=Math.min(mWordX[i],mTotalWidth - getWidth());
      break;
    }
    i++;
  }
  updateScrollPosition(targetX);
}
Program: 88348
Project: 88348
Buggy source:
public void scrollPrev(){
  int i=0;
  final int count=mSuggestions.size();
  int firstItem=0;
  while (i < count) {
    if (mWordX[i] < getScrollX() && mWordX[i] + mWordWidth[i] >= getScrollX() - 1) {
      firstItem=i;
      break;
    }
    i++;
  }
  int leftEdge=mWordX[firstItem] + mWordWidth[firstItem] - getWidth();
  if (leftEdge < 0)   leftEdge=0;
  updateScrollPosition(leftEdge);
}

Fixed version (ground truth):
public void scrollPrev(){
  int i=0;
  final int count=Math.min(mSuggestions.size(),MAX_SUGGESTIONS);
  int firstItem=0;
  while (i < count) {
    if (mWordX[i] < getScrollX() && mWordX[i] + mWordWidth[i] >= getScrollX() - 1) {
      firstItem=i;
      break;
    }
    i++;
  }
  int leftEdge=mWordX[firstItem] + mWordWidth[firstItem] - getWidth();
  if (leftEdge < 0)   leftEdge=0;
  updateScrollPosition(leftEdge);
}
Program: 88353
Project: 88353
Buggy source:
private boolean openExtension(){
  if (((LatinKeyboard)getKeyboard()).getExtension() == 0)   return false;
  makePopupWindow();
  mExtensionVisible=true;
  return true;
}

Fixed version (ground truth):
private boolean openExtension(){
  if (!isShown()) {
    return false;
  }
  if (((LatinKeyboard)getKeyboard()).getExtension() == 0)   return false;
  makePopupWindow();
  mExtensionVisible=true;
  return true;
}
Program: 88355
Project: 88355
Buggy source:
@Override public void onConfigurationChanged(Configuration conf){
  if (!TextUtils.equals(conf.locale.toString(),mLocale)) {
    if (mLanguageSwitcher != null) {
      mLanguageSwitcher.loadLocales(PreferenceManager.getDefaultSharedPreferences(this));
      toggleLanguage(true,true);
    }
 else {
      reloadKeyboards();
    }
  }
  if (conf.orientation != mOrientation) {
    InputConnection ic=getCurrentInputConnection();
    commitTyped(ic);
    if (ic != null)     ic.finishComposingText();
    mOrientation=conf.orientation;
    reloadKeyboards();
  }
  mConfigurationChanging=true;
  super.onConfigurationChanged(conf);
  if (mRecognizing) {
    switchToRecognitionStatusView();
  }
  mConfigurationChanging=false;
}

Fixed version (ground truth):
@Override public void onConfigurationChanged(Configuration conf){
  final String systemLocale=conf.locale.toString();
  if (!TextUtils.equals(systemLocale,mSystemLocale)) {
    mSystemLocale=systemLocale;
    if (mLanguageSwitcher != null) {
      mLanguageSwitcher.loadLocales(PreferenceManager.getDefaultSharedPreferences(this));
      toggleLanguage(true,true);
    }
 else {
      reloadKeyboards();
    }
  }
  if (conf.orientation != mOrientation) {
    InputConnection ic=getCurrentInputConnection();
    commitTyped(ic);
    if (ic != null)     ic.finishComposingText();
    mOrientation=conf.orientation;
    reloadKeyboards();
  }
  mConfigurationChanging=true;
  super.onConfigurationChanged(conf);
  if (mRecognizing) {
    switchToRecognitionStatusView();
  }
  mConfigurationChanging=false;
}
Program: 88356
Project: 88356
Buggy source:
private void initSuggest(String locale){
  mLocale=locale;
  Resources orig=getResources();
  Configuration conf=orig.getConfiguration();
  Locale saveLocale=conf.locale;
  conf.locale=new Locale(locale);
  orig.updateConfiguration(conf,orig.getDisplayMetrics());
  if (mSuggest != null) {
    mSuggest.close();
  }
  SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
  mQuickFixes=sp.getBoolean(PREF_QUICK_FIXES,true);
  mSuggest=new Suggest(this,R.raw.main);
  updateAutoTextEnabled(saveLocale);
  if (mUserDictionary != null)   mUserDictionary.close();
  mUserDictionary=new UserDictionary(this,mLocale);
  if (mContactsDictionary == null) {
    mContactsDictionary=new ContactsDictionary(this);
  }
  if (mAutoDictionary != null) {
    mAutoDictionary.close();
  }
  mAutoDictionary=new AutoDictionary(this,this,mLocale);
  mSuggest.setUserDictionary(mUserDictionary);
  mSuggest.setContactsDictionary(mContactsDictionary);
  mSuggest.setAutoDictionary(mAutoDictionary);
  updateCorrectionMode();
  mWordSeparators=mResources.getString(R.string.word_separators);
  mSentenceSeparators=mResources.getString(R.string.sentence_separators);
  conf.locale=saveLocale;
  orig.updateConfiguration(conf,orig.getDisplayMetrics());
}

Fixed version (ground truth):
private void initSuggest(String locale){
  mInputLocale=locale;
  Resources orig=getResources();
  Configuration conf=orig.getConfiguration();
  Locale saveLocale=conf.locale;
  conf.locale=new Locale(locale);
  orig.updateConfiguration(conf,orig.getDisplayMetrics());
  if (mSuggest != null) {
    mSuggest.close();
  }
  SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
  mQuickFixes=sp.getBoolean(PREF_QUICK_FIXES,true);
  mSuggest=new Suggest(this,R.raw.main);
  updateAutoTextEnabled(saveLocale);
  if (mUserDictionary != null)   mUserDictionary.close();
  mUserDictionary=new UserDictionary(this,mInputLocale);
  if (mContactsDictionary == null) {
    mContactsDictionary=new ContactsDictionary(this);
  }
  if (mAutoDictionary != null) {
    mAutoDictionary.close();
  }
  mAutoDictionary=new AutoDictionary(this,this,mInputLocale);
  mSuggest.setUserDictionary(mUserDictionary);
  mSuggest.setContactsDictionary(mContactsDictionary);
  mSuggest.setAutoDictionary(mAutoDictionary);
  updateCorrectionMode();
  mWordSeparators=mResources.getString(R.string.word_separators);
  mSentenceSeparators=mResources.getString(R.string.sentence_separators);
  conf.locale=saveLocale;
  orig.updateConfiguration(conf,orig.getDisplayMetrics());
}
Program: 88357
Project: 88357
Buggy source:
@Override public void onCreate(){
  super.onCreate();
  mResources=getResources();
  final Configuration conf=mResources.getConfiguration();
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  mLanguageSwitcher=new LanguageSwitcher(this);
  mLanguageSwitcher.loadLocales(prefs);
  mKeyboardSwitcher=new KeyboardSwitcher(this,this);
  mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
  boolean enableMultipleLanguages=mLanguageSwitcher.getLocaleCount() > 0;
  String inputLanguage=mLanguageSwitcher.getInputLanguage();
  if (inputLanguage == null) {
    inputLanguage=conf.locale.toString();
  }
  initSuggest(inputLanguage);
  mOrientation=conf.orientation;
  initSuggestPuncList();
  IntentFilter filter=new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
  registerReceiver(mReceiver,filter);
  if (VOICE_INSTALLED) {
    mVoiceInput=new VoiceInput(this,this);
    mHints=new Hints(this,new Hints.Display(){
      public void showHint(      int viewResource){
        LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(viewResource,null);
        setCandidatesView(view);
        setCandidatesViewShown(true);
        mIsShowingHint=true;
      }
    }
);
  }
  prefs.registerOnSharedPreferenceChangeListener(this);
}

Fixed version (ground truth):
@Override public void onCreate(){
  super.onCreate();
  mResources=getResources();
  final Configuration conf=mResources.getConfiguration();
  final SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  mLanguageSwitcher=new LanguageSwitcher(this);
  mLanguageSwitcher.loadLocales(prefs);
  mKeyboardSwitcher=new KeyboardSwitcher(this,this);
  mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
  mSystemLocale=conf.locale.toString();
  String inputLanguage=mLanguageSwitcher.getInputLanguage();
  if (inputLanguage == null) {
    inputLanguage=conf.locale.toString();
  }
  initSuggest(inputLanguage);
  mOrientation=conf.orientation;
  initSuggestPuncList();
  IntentFilter filter=new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
  registerReceiver(mReceiver,filter);
  if (VOICE_INSTALLED) {
    mVoiceInput=new VoiceInput(this,this);
    mHints=new Hints(this,new Hints.Display(){
      public void showHint(      int viewResource){
        LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(viewResource,null);
        setCandidatesView(view);
        setCandidatesViewShown(true);
        mIsShowingHint=true;
      }
    }
);
  }
  prefs.registerOnSharedPreferenceChangeListener(this);
}
Program: 88358
Project: 88358
Buggy source:
private void updateAutoTextEnabled(Locale systemLocale){
  if (mSuggest == null)   return;
  boolean different=!systemLocale.getLanguage().equalsIgnoreCase(mLocale.substring(0,2));
  mSuggest.setAutoTextEnabled(!different && mQuickFixes);
}

Fixed version (ground truth):
private void updateAutoTextEnabled(Locale systemLocale){
  if (mSuggest == null)   return;
  boolean different=!systemLocale.getLanguage().equalsIgnoreCase(mInputLocale.substring(0,2));
  mSuggest.setAutoTextEnabled(!different && mQuickFixes);
}
Program: 88359
Project: 88359
Buggy source:
private boolean openExtension(){
  if (((LatinKeyboard)getKeyboard()).getExtension() == 0)   return false;
  makePopupWindow();
  mExtensionVisible=true;
  return true;
}

Fixed version (ground truth):
private boolean openExtension(){
  if (!isShown()) {
    return false;
  }
  if (((LatinKeyboard)getKeyboard()).getExtension() == 0)   return false;
  makePopupWindow();
  mExtensionVisible=true;
  return true;
}
Program: 88360
Project: 88360
Buggy source:
/** 
 * Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
 * @param codes the array of unicode values
 */
public void add(int primaryCode,int[] codes){
  mTypedWord.append((char)primaryCode);
  mCodes.add(codes);
  if (Character.isUpperCase((char)primaryCode))   mCapsCount++;
}

Fixed version (ground truth):
/** 
 * Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
 * @param codes the array of unicode values
 */
public void add(int primaryCode,int[] codes){
  mTypedWord.append((char)primaryCode);
  correctPrimaryJuxtapos(primaryCode,codes);
  mCodes.add(codes);
  if (Character.isUpperCase((char)primaryCode))   mCapsCount++;
}
Program: 88361
Project: 88361
Buggy source:
private boolean shouldShowVoiceButton(FieldContext fieldContext,EditorInfo attribute){
  return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !(attribute != null && attribute.privateImeOptions != null && attribute.privateImeOptions.equals(IME_OPTION_NO_MICROPHONE))&& RecognitionManager.isRecognitionAvailable(this);
}

Fixed version (ground truth):
private boolean shouldShowVoiceButton(FieldContext fieldContext,EditorInfo attribute){
  return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !(attribute != null && attribute.privateImeOptions != null && attribute.privateImeOptions.equals(IME_OPTION_NO_MICROPHONE))&& SpeechRecognizer.isRecognitionAvailable(this);
}
Program: 88362
Project: 88362
Buggy source:
@Override protected void onResume(){
  super.onResume();
  int autoTextSize=AutoText.getSize(getListView());
  if (autoTextSize < 1) {
    ((PreferenceGroup)findPreference(PREDICTION_SETTINGS_KEY)).removePreference(mQuickFixes);
  }
  if (!LatinIME.VOICE_INSTALLED || !RecognitionManager.isRecognitionAvailable(this)) {
    getPreferenceScreen().removePreference(mVoicePreference);
  }
 else {
    updateVoiceModeSummary();
  }
}

Fixed version (ground truth):
@Override protected void onResume(){
  super.onResume();
  int autoTextSize=AutoText.getSize(getListView());
  if (autoTextSize < 1) {
    ((PreferenceGroup)findPreference(PREDICTION_SETTINGS_KEY)).removePreference(mQuickFixes);
  }
  if (!LatinIME.VOICE_INSTALLED || !SpeechRecognizer.isRecognitionAvailable(this)) {
    getPreferenceScreen().removePreference(mVoicePreference);
  }
 else {
    updateVoiceModeSummary();
  }
}
Program: 88363
Project: 88363
Buggy source:
/** 
 * Cancel in-progress speech recognition.
 */
public void cancel(){
switch (mState) {
case LISTENING:
    mLogger.cancelDuringListening();
  break;
case WORKING:
mLogger.cancelDuringWorking();
break;
case ERROR:
mLogger.cancelDuringError();
break;
}
mState=DEFAULT;
mHandler.removeMessages(MSG_CLOSE_ERROR_DIALOG);
mRecognitionManager.cancel();
mUiListener.onCancelVoice();
mRecognitionView.finish();
}

Fixed version (ground truth):
/** 
 * Cancel in-progress speech recognition.
 */
public void cancel(){
switch (mState) {
case LISTENING:
    mLogger.cancelDuringListening();
  break;
case WORKING:
mLogger.cancelDuringWorking();
break;
case ERROR:
mLogger.cancelDuringError();
break;
}
mState=DEFAULT;
mHandler.removeMessages(MSG_CLOSE_ERROR_DIALOG);
mSpeechRecognizer.cancel();
mUiListener.onCancelVoice();
mRecognitionView.finish();
}
Program: 88364
Project: 88364
Buggy source:
public void onResults(Bundle resultsBundle){
  List<String> results=resultsBundle.getStringArrayList(RecognitionManager.RESULTS_RECOGNITION);
  mState=DEFAULT;
  final Map<String,List<CharSequence>> alternatives=new HashMap<String,List<CharSequence>>();
  if (results.size() >= 2 && ENABLE_WORD_CORRECTIONS) {
    final String[][] words=new String[results.size()][];
    for (int i=0; i < words.length; i++) {
      words[i]=results.get(i).split("String_Node_Str");
    }
    for (int key=0; key < words[0].length; key++) {
      alternatives.put(words[0][key],new ArrayList<CharSequence>());
      for (int alt=1; alt < words.length; alt++) {
        int keyBegin=key * words[alt].length / words[0].length;
        int keyEnd=(key + 1) * words[alt].length / words[0].length;
        for (int i=keyBegin; i < Math.min(words[alt].length,keyEnd); i++) {
          List<CharSequence> altList=alternatives.get(words[0][key]);
          if (!altList.contains(words[alt][i]) && altList.size() < 6) {
            altList.add(words[alt][i]);
          }
        }
      }
    }
  }
  if (results.size() > 5) {
    results=results.subList(0,5);
  }
  mUiListener.onVoiceResults(results,alternatives);
  mRecognitionView.finish();
}

Fixed version (ground truth):
public void onResults(Bundle resultsBundle){
  List<String> results=resultsBundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
  mState=DEFAULT;
  final Map<String,List<CharSequence>> alternatives=new HashMap<String,List<CharSequence>>();
  if (results.size() >= 2 && ENABLE_WORD_CORRECTIONS) {
    final String[][] words=new String[results.size()][];
    for (int i=0; i < words.length; i++) {
      words[i]=results.get(i).split("String_Node_Str");
    }
    for (int key=0; key < words[0].length; key++) {
      alternatives.put(words[0][key],new ArrayList<CharSequence>());
      for (int alt=1; alt < words.length; alt++) {
        int keyBegin=key * words[alt].length / words[0].length;
        int keyEnd=(key + 1) * words[alt].length / words[0].length;
        for (int i=keyBegin; i < Math.min(words[alt].length,keyEnd); i++) {
          List<CharSequence> altList=alternatives.get(words[0][key]);
          if (!altList.contains(words[alt][i]) && altList.size() < 6) {
            altList.add(words[alt][i]);
          }
        }
      }
    }
  }
  if (results.size() > 5) {
    results=results.subList(0,5);
  }
  mUiListener.onVoiceResults(results,alternatives);
  mRecognitionView.finish();
}
Program: 88365
Project: 88365
Buggy source:
private int getErrorStringId(int errorType,boolean endpointed){
switch (errorType) {
case RecognitionManager.ERROR_CLIENT:
    return R.string.voice_not_installed;
case RecognitionManager.ERROR_NETWORK:
  return R.string.voice_network_error;
case RecognitionManager.ERROR_NETWORK_TIMEOUT:
return endpointed ? R.string.voice_network_error : R.string.voice_too_much_speech;
case RecognitionManager.ERROR_AUDIO:
return R.string.voice_audio_error;
case RecognitionManager.ERROR_SERVER:
return R.string.voice_server_error;
case RecognitionManager.ERROR_SPEECH_TIMEOUT:
return R.string.voice_speech_timeout;
case RecognitionManager.ERROR_NO_MATCH:
return R.string.voice_no_match;
default :
return R.string.voice_error;
}
}

Fixed version (ground truth):
private int getErrorStringId(int errorType,boolean endpointed){
switch (errorType) {
case SpeechRecognizer.ERROR_CLIENT:
    return R.string.voice_not_installed;
case SpeechRecognizer.ERROR_NETWORK:
  return R.string.voice_network_error;
case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
return endpointed ? R.string.voice_network_error : R.string.voice_too_much_speech;
case SpeechRecognizer.ERROR_AUDIO:
return R.string.voice_audio_error;
case SpeechRecognizer.ERROR_SERVER:
return R.string.voice_server_error;
case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
return R.string.voice_speech_timeout;
case SpeechRecognizer.ERROR_NO_MATCH:
return R.string.voice_no_match;
default :
return R.string.voice_error;
}
}
Program: 88366
Project: 88366
Buggy source:
/** 
 * @param context the service or activity in which we're running.
 * @param uiHandler object to receive events from VoiceInput.
 */
public VoiceInput(Context context,UiListener uiHandler){
  mLogger=VoiceInputLogger.getLogger(context);
  mRecognitionListener=new ImeRecognitionListener();
  mRecognitionManager=RecognitionManager.createRecognitionManager(context);
  mRecognitionManager.setRecognitionListener(mRecognitionListener);
  mUiListener=uiHandler;
  mContext=context;
  newView();
  String recommendedPackages=SettingsUtil.getSettingsString(context.getContentResolver(),SettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,DEFAULT_RECOMMENDED_PACKAGES);
  mRecommendedList=new Whitelist();
  for (  String recommendedPackage : recommendedPackages.split("String_Node_Str")) {
    mRecommendedList.addApp(recommendedPackage);
  }
  mBlacklist=new Whitelist();
  mBlacklist.addApp("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * @param context the service or activity in which we're running.
 * @param uiHandler object to receive events from VoiceInput.
 */
public VoiceInput(Context context,UiListener uiHandler){
  mLogger=VoiceInputLogger.getLogger(context);
  mRecognitionListener=new ImeRecognitionListener();
  mSpeechRecognizer=SpeechRecognizer.createSpeechRecognizer(context);
  mSpeechRecognizer.setRecognitionListener(mRecognitionListener);
  mUiListener=uiHandler;
  mContext=context;
  newView();
  String recommendedPackages=SettingsUtil.getSettingsString(context.getContentResolver(),SettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES,DEFAULT_RECOMMENDED_PACKAGES);
  mRecommendedList=new Whitelist();
  for (  String recommendedPackage : recommendedPackages.split("String_Node_Str")) {
    mRecommendedList.addApp(recommendedPackage);
  }
  mBlacklist=new Whitelist();
  mBlacklist.addApp("String_Node_Str");
}
Program: 88367
Project: 88367
Buggy source:
public void destroy(){
  mRecognitionManager.destroy();
}

Fixed version (ground truth):
public void destroy(){
  mSpeechRecognizer.destroy();
}
Program: 88368
Project: 88368
Buggy source:
/** 
 * Called only when the recognition manager's initialization completed
 * @param context context with which {@link #startListening(FieldContext,boolean)} was executed
 */
private void startListeningAfterInitialization(FieldContext context){
  Intent intent=makeIntent();
  intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,"String_Node_Str");
  intent.putExtra(EXTRA_RECOGNITION_CONTEXT,context.getBundle());
  intent.putExtra(EXTRA_CALLING_PACKAGE,"String_Node_Str");
  intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,SettingsUtil.getSettingsInt(mContext.getContentResolver(),SettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,1));
  final ContentResolver cr=mContext.getContentResolver();
  putEndpointerExtra(cr,intent,SettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS,null);
  putEndpointerExtra(cr,intent,SettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS);
  putEndpointerExtra(cr,intent,SettingsUtil.LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,null);
  mRecognitionManager.startListening(intent);
}

Fixed version (ground truth):
/** 
 * Called only when the recognition manager's initialization completed
 * @param context context with which {@link #startListening(FieldContext,boolean)} was executed
 */
private void startListeningAfterInitialization(FieldContext context){
  Intent intent=makeIntent();
  intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,"String_Node_Str");
  intent.putExtra(EXTRA_RECOGNITION_CONTEXT,context.getBundle());
  intent.putExtra(EXTRA_CALLING_PACKAGE,"String_Node_Str");
  intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,SettingsUtil.getSettingsInt(mContext.getContentResolver(),SettingsUtil.LATIN_IME_MAX_VOICE_RESULTS,1));
  final ContentResolver cr=mContext.getContentResolver();
  putEndpointerExtra(cr,intent,SettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS,EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS,null);
  putEndpointerExtra(cr,intent,SettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS,INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS);
  putEndpointerExtra(cr,intent,SettingsUtil.LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS,null);
  mSpeechRecognizer.startListening(intent);
}
Program: 88369
Project: 88369
Buggy source:
/** 
 * Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
 * @param codes the array of unicode values
 */
public void add(int primaryCode,int[] codes){
  mTypedWord.append((char)primaryCode);
  mCodes.add(codes);
  if (Character.isUpperCase((char)primaryCode))   mCapsCount++;
}

Fixed version (ground truth):
/** 
 * Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
 * @param codes the array of unicode values
 */
public void add(int primaryCode,int[] codes){
  mTypedWord.append((char)primaryCode);
  correctPrimaryJuxtapos(primaryCode,codes);
  mCodes.add(codes);
  if (Character.isUpperCase((char)primaryCode))   mCapsCount++;
}
Program: 88370
Project: 88370
Buggy source:
private void pickDefaultSuggestion(){
  if (mHandler.hasMessages(MSG_UPDATE_SUGGESTIONS)) {
    mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
    updateSuggestions();
  }
  if (mBestWord != null) {
    TextEntryState.acceptedDefault(mWord.getTypedWord(),mBestWord);
    mJustAccepted=true;
    pickSuggestion(mBestWord);
    checkAddToDictionary(mBestWord,AutoDictionary.FREQUENCY_FOR_TYPED);
  }
}

Fixed version (ground truth):
private void pickDefaultSuggestion(){
  if (mHandler.hasMessages(MSG_UPDATE_SUGGESTIONS)) {
    mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
    updateSuggestions();
  }
  if (mBestWord != null && mBestWord.length() > 0) {
    TextEntryState.acceptedDefault(mWord.getTypedWord(),mBestWord);
    mJustAccepted=true;
    pickSuggestion(mBestWord);
    checkAddToDictionary(mBestWord,AutoDictionary.FREQUENCY_FOR_TYPED);
  }
}
Program: 88371
Project: 88371
Buggy source:
private void maybeRemovePreviousPeriod(CharSequence text){
  final InputConnection ic=getCurrentInputConnection();
  if (ic == null)   return;
  CharSequence lastOne=ic.getTextBeforeCursor(1,0);
  if (lastOne != null && lastOne.length() == 1 && lastOne.charAt(0) == '.' && text.charAt(0) == '.') {
    ic.deleteSurroundingText(1,0);
  }
}

Fixed version (ground truth):
private void maybeRemovePreviousPeriod(CharSequence text){
  final InputConnection ic=getCurrentInputConnection();
  if (ic == null)   return;
  CharSequence lastOne=ic.getTextBeforeCursor(1,0);
  if (lastOne != null && lastOne.length() == 1 && lastOne.charAt(0) == KEYCODE_PERIOD && text.charAt(0) == KEYCODE_PERIOD) {
    ic.deleteSurroundingText(1,0);
  }
}
Program: 88372
Project: 88372
Buggy source:
private void handleSeparator(int primaryCode){
  if (VOICE_INSTALLED && mVoiceInputHighlighted) {
    commitVoiceInput();
  }
  boolean pickedDefault=false;
  InputConnection ic=getCurrentInputConnection();
  if (ic != null) {
    ic.beginBatchEdit();
  }
  if (mPredicting) {
    if (mAutoCorrectOn && primaryCode != '\'' && (mJustRevertedSeparator == null || mJustRevertedSeparator.length() == 0 || mJustRevertedSeparator.charAt(0) != primaryCode)) {
      pickDefaultSuggestion();
      pickedDefault=true;
      if (primaryCode == KEYCODE_SPACE) {
        mJustAddedAutoSpace=true;
      }
    }
 else {
      commitTyped(ic);
    }
  }
  if (mJustAddedAutoSpace && primaryCode == KEYCODE_ENTER) {
    removeTrailingSpace();
    mJustAddedAutoSpace=false;
  }
  sendKeyChar((char)primaryCode);
  TextEntryState.typedCharacter((char)primaryCode,true);
  if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED && primaryCode != KEYCODE_ENTER) {
    swapPunctuationAndSpace();
  }
 else   if (isPredictionOn() && primaryCode == KEYCODE_SPACE) {
    doubleSpace();
  }
  if (pickedDefault && mBestWord != null) {
    TextEntryState.acceptedDefault(mWord.getTypedWord(),mBestWord);
  }
  updateShiftKeyState(getCurrentInputEditorInfo());
  if (ic != null) {
    ic.endBatchEdit();
  }
}

Fixed version (ground truth):
private void handleSeparator(int primaryCode){
  if (VOICE_INSTALLED && mVoiceInputHighlighted) {
    commitVoiceInput();
  }
  boolean pickedDefault=false;
  InputConnection ic=getCurrentInputConnection();
  if (ic != null) {
    ic.beginBatchEdit();
  }
  if (mPredicting) {
    if (mAutoCorrectOn && primaryCode != '\'' && (mJustRevertedSeparator == null || mJustRevertedSeparator.length() == 0 || mJustRevertedSeparator.charAt(0) != primaryCode)) {
      pickDefaultSuggestion();
      pickedDefault=true;
      if (primaryCode == KEYCODE_SPACE) {
        mJustAddedAutoSpace=true;
      }
    }
 else {
      commitTyped(ic);
    }
  }
  if (mJustAddedAutoSpace && primaryCode == KEYCODE_ENTER) {
    removeTrailingSpace();
    mJustAddedAutoSpace=false;
  }
  sendKeyChar((char)primaryCode);
  if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED && primaryCode == KEYCODE_PERIOD) {
    reswapPeriodAndSpace();
  }
  TextEntryState.typedCharacter((char)primaryCode,true);
  if (TextEntryState.getState() == TextEntryState.STATE_PUNCTUATION_AFTER_ACCEPTED && primaryCode != KEYCODE_ENTER) {
    swapPunctuationAndSpace();
  }
 else   if (isPredictionOn() && primaryCode == KEYCODE_SPACE) {
    doubleSpace();
  }
  if (pickedDefault && mBestWord != null) {
    TextEntryState.acceptedDefault(mWord.getTypedWord(),mBestWord);
  }
  updateShiftKeyState(getCurrentInputEditorInfo());
  if (ic != null) {
    ic.endBatchEdit();
  }
}
Program: 88373
Project: 88373
Buggy source:
public void onText(CharSequence text){
  InputConnection ic=getCurrentInputConnection();
  if (ic == null)   return;
  ic.beginBatchEdit();
  if (mPredicting) {
    commitTyped(ic);
  }
  maybeRemovePreviousPeriod(text);
  ic.commitText(text,1);
  ic.endBatchEdit();
  updateShiftKeyState(getCurrentInputEditorInfo());
  mJustRevertedSeparator=null;
  mJustAddedAutoSpace=false;
}

Fixed version (ground truth):
public void onText(CharSequence text){
  if (VOICE_INSTALLED && mVoiceInputHighlighted) {
    commitVoiceInput();
  }
  InputConnection ic=getCurrentInputConnection();
  if (ic == null)   return;
  ic.beginBatchEdit();
  if (mPredicting) {
    commitTyped(ic);
  }
  maybeRemovePreviousPeriod(text);
  ic.commitText(text,1);
  ic.endBatchEdit();
  updateShiftKeyState(getCurrentInputEditorInfo());
  mJustRevertedSeparator=null;
  mJustAddedAutoSpace=false;
}
Program: 88374
Project: 88374
Buggy source:
private void reloadKeyboards(){
  if (mKeyboardSwitcher == null) {
    mKeyboardSwitcher=new KeyboardSwitcher(this,this);
  }
  mKeyboardSwitcher.setInputLocale(new Locale(mInputLanguage),getSelectedInputLanguages() != null);
  mKeyboardSwitcher.setVoiceMode(mEnableVoice,mVoiceOnPrimary);
  mKeyboardSwitcher.makeKeyboards(true);
}

Fixed version (ground truth):
private void reloadKeyboards(){
  if (mKeyboardSwitcher == null) {
    mKeyboardSwitcher=new KeyboardSwitcher(this,this);
  }
  mKeyboardSwitcher.setInputLocale(new Locale(mInputLanguage),getSelectedInputLanguages() != null);
  if (mInputView != null) {
    mKeyboardSwitcher.setVoiceMode(mEnableVoice,mVoiceOnPrimary);
  }
  mKeyboardSwitcher.makeKeyboards(true);
}
Program: 88375
Project: 88375
Buggy source:
public void showInitializing(){
  mUiHandler.post(new Runnable(){
    public void run(){
      mProgress.setVisibility(View.GONE);
      mText.setText(R.string.voice_initializing);
      mImage.setImageDrawable(mInitializing);
      mButtonText.setText(mContext.getText(R.string.cancel));
    }
  }
);
}

Fixed version (ground truth):
public void showInitializing(){
  mUiHandler.post(new Runnable(){
    public void run(){
      prepareDialog(false,mContext.getText(R.string.voice_initializing),mInitializing,mContext.getText(R.string.cancel));
    }
  }
);
}
Program: 88376
Project: 88376
Buggy source:
public void run(){
  exitWorking();
}

Fixed version (ground truth):
public void run(){
  mState=State.READY;
  exitWorking();
}
Program: 88377
Project: 88377
Buggy source:
public void showError(final String message){
  mState=State.READY;
  mUiHandler.post(new Runnable(){
    public void run(){
      exitWorking();
      mText.setText(message);
      mImage.setImageDrawable(mError);
      mButtonText.setText(mContext.getText(R.string.ok));
    }
  }
);
}

Fixed version (ground truth):
public void showError(final String message){
  mUiHandler.post(new Runnable(){
    public void run(){
      mState=State.READY;
      prepareDialog(false,message,mError,mContext.getText(R.string.ok));
    }
  }
);
}
Program: 88378
Project: 88378
Buggy source:
public void finish(){
  mState=State.READY;
  mUiHandler.post(new Runnable(){
    public void run(){
      exitWorking();
    }
  }
);
  showStartState();
}

Fixed version (ground truth):
public void finish(){
  mUiHandler.post(new Runnable(){
    public void run(){
      mState=State.READY;
      exitWorking();
    }
  }
);
}
Program: 88379
Project: 88379
Buggy source:
public void showListening(){
  mState=State.LISTENING;
  mUiHandler.post(new Runnable(){
    public void run(){
      mText.setText(R.string.voice_listening);
      mImage.setImageDrawable(mSpeakNow.get(0));
      mButtonText.setText(mContext.getText(R.string.cancel));
    }
  }
);
  mUiHandler.postDelayed(mUpdateVolumeRunnable,50);
}

Fixed version (ground truth):
public void showListening(){
  mUiHandler.post(new Runnable(){
    public void run(){
      mState=State.LISTENING;
      prepareDialog(false,mContext.getText(R.string.voice_listening),mSpeakNow.get(0),mContext.getText(R.string.cancel));
    }
  }
);
  mUiHandler.postDelayed(mUpdateVolumeRunnable,50);
}
Program: 88380
Project: 88380
Buggy source:
public void showWorking(final ByteArrayOutputStream waveBuffer,final int speechStartPosition,final int speechEndPosition){
  mState=State.WORKING;
  mUiHandler.post(new Runnable(){
    public void run(){
      mText.setText(R.string.voice_working);
      mImage.setVisibility(View.GONE);
      mProgress.setVisibility(View.VISIBLE);
      final ShortBuffer buf=ByteBuffer.wrap(waveBuffer.toByteArray()).order(ByteOrder.nativeOrder()).asShortBuffer();
      buf.position(0);
      waveBuffer.reset();
      showWave(buf,speechStartPosition / 2,speechEndPosition / 2);
    }
  }
);
}

Fixed version (ground truth):
public void showWorking(final ByteArrayOutputStream waveBuffer,final int speechStartPosition,final int speechEndPosition){
  mUiHandler.post(new Runnable(){
    public void run(){
      mState=State.WORKING;
      prepareDialog(true,mContext.getText(R.string.voice_working),null,mContext.getText(R.string.cancel));
      final ShortBuffer buf=ByteBuffer.wrap(waveBuffer.toByteArray()).order(ByteOrder.nativeOrder()).asShortBuffer();
      buf.position(0);
      waveBuffer.reset();
      showWave(buf,speechStartPosition / 2,speechEndPosition / 2);
    }
  }
);
}