nus-yam/ex-repair huggingface dataset:
Program: 87739
Project: 87739
Buggy source:
/** 
 * Waits for any publication requests to finish and closes the   {@link JsonWriter} used foroutput. See class comment for details about  {@code JsonWriter} construction.
 * @param onClosed run after the close() operation has completed asynchronously
 */
private synchronized void close(final Runnable onClosed){
  mExecutor.submit(new Callable<Object>(){
    @Override public Object call() throws Exception {
      try {
        if (mHasWrittenData) {
          mJsonWriter.endArray();
          mHasWrittenData=false;
        }
        mJsonWriter.flush();
        mJsonWriter.close();
        if (DEBUG) {
          Log.d(TAG,"String_Node_Str" + mFile);
        }
      }
 catch (      Exception e) {
        Log.d(TAG,"String_Node_Str",e);
      }
 finally {
        if (mFile != null && mFile.exists()) {
          mFile.setWritable(false,false);
        }
        if (onClosed != null) {
          onClosed.run();
        }
      }
      return null;
    }
  }
);
  removeAnyScheduledFlush();
  mExecutor.shutdown();
}

Fixed version (ground truth):
/** 
 * Waits for any publication requests to finish and closes the   {@link JsonWriter} used foroutput. See class comment for details about  {@code JsonWriter} construction.
 * @param onClosed run after the close() operation has completed asynchronously
 */
private synchronized void close(final Runnable onClosed){
  mExecutor.submit(new Callable<Object>(){
    @Override public Object call() throws Exception {
      try {
        if (!mHasWrittenData) {
          mJsonWriter.beginArray();
        }
        mJsonWriter.endArray();
        mHasWrittenData=false;
        mJsonWriter.flush();
        mJsonWriter.close();
        if (DEBUG) {
          Log.d(TAG,"String_Node_Str" + mFile);
        }
      }
 catch (      Exception e) {
        Log.d(TAG,"String_Node_Str",e);
      }
 finally {
        if (mFile != null && mFile.exists()) {
          mFile.setWritable(false,false);
        }
        if (onClosed != null) {
          onClosed.run();
        }
      }
      return null;
    }
  }
);
  removeAnyScheduledFlush();
  mExecutor.shutdown();
}
Program: 87740
Project: 87740
Buggy source:
/** 
 * Arrange for the UploaderService to be run on a regular basis. Any existing scheduled invocation of UploaderService is removed and optionally rescheduled. This may cause problems if this method is called so often that no scheduled invocation is ever run.  But if the delay is short enough that it will go off when the user is sleeping, then there should be no starvation.
 * @param context {@link Context} object
 * @param needsRescheduling whether to schedule a future intent to be delivered to this service
 */
public static void cancelAndRescheduleUploadingService(final Context context,final boolean needsRescheduling){
  final PendingIntent pendingIntent=getPendingIntentForService(context);
  final AlarmManager alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
  cancelAnyScheduledServiceAlarm(alarmManager,pendingIntent);
  if (needsRescheduling) {
    scheduleServiceAlarm(alarmManager,pendingIntent);
  }
}

Fixed version (ground truth):
/** 
 * Arrange for the UploaderService to be run on a regular basis. Any existing scheduled invocation of UploaderService is removed and optionally rescheduled. This may cause problems if this method is called so often that no scheduled invocation is ever run.  But if the delay is short enough that it will go off when the user is sleeping, then there should be no starvation.
 * @param context {@link Context} object
 * @param needsRescheduling whether to schedule a future intent to be delivered to this service
 */
public static void cancelAndRescheduleUploadingService(final Context context,final boolean needsRescheduling){
  final Intent intent=new Intent(context,UploaderService.class);
  final PendingIntent pendingIntent=PendingIntent.getService(context,0,intent,0);
  final AlarmManager alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
  alarmManager.cancel(pendingIntent);
  if (needsRescheduling) {
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime() + UploaderService.RUN_INTERVAL,pendingIntent);
  }
}
Program: 87741
Project: 87741
Buggy source:
private boolean isDevTeamBuild(){
  try {
    final PackageInfo packageInfo;
    packageInfo=mLatinIME.getPackageManager().getPackageInfo(mLatinIME.getPackageName(),0);
    final String versionName=packageInfo.versionName;
    return !(developerBuildRegex.matcher(versionName).find());
  }
 catch (  final NameNotFoundException e) {
    Log.e(TAG,"String_Node_Str",e);
    return false;
  }
}

Fixed version (ground truth):
private boolean isDevTeamBuild(){
  try {
    final PackageInfo packageInfo;
    packageInfo=mLatinIME.getPackageManager().getPackageInfo(mLatinIME.getPackageName(),0);
    final String versionName=packageInfo.versionName;
    return developerBuildRegex.matcher(versionName).find();
  }
 catch (  final NameNotFoundException e) {
    Log.e(TAG,"String_Node_Str",e);
    return false;
  }
}
Program: 87742
Project: 87742
Buggy source:
/** 
 * Waits for publication requests to finish, closes the JsonWriter, but then deletes the backing output file.
 * @param onAbort run after the abort() operation has completed asynchronously
 */
private synchronized void abort(final Runnable onAbort){
  mExecutor.submit(new Callable<Object>(){
    @Override public Object call() throws Exception {
      try {
        if (mHasWrittenData) {
          mJsonWriter.endArray();
          mJsonWriter.close();
          mHasWrittenData=false;
        }
      }
  finally {
        if (mFile != null) {
          mFile.delete();
        }
        if (onAbort != null) {
          onAbort.run();
        }
      }
      return null;
    }
  }
);
  removeAnyScheduledFlush();
  mExecutor.shutdown();
}

Fixed version (ground truth):
/** 
 * Waits for publication requests to finish, closes the JsonWriter, but then deletes the backing output file.
 * @param onAbort run after the abort() operation has completed asynchronously
 */
private synchronized void abort(final Runnable onAbort){
  mExecutor.submit(new Callable<Object>(){
    @Override public Object call() throws Exception {
      try {
        if (mHasWrittenData) {
          if (!mHasWrittenData) {
            mJsonWriter.beginArray();
          }
          mJsonWriter.endArray();
          mJsonWriter.close();
          mHasWrittenData=false;
        }
      }
  finally {
        if (mFile != null) {
          mFile.delete();
        }
        if (onAbort != null) {
          onAbort.run();
        }
      }
      return null;
    }
  }
);
  removeAnyScheduledFlush();
  mExecutor.shutdown();
}
Program: 87743
Project: 87743
Buggy source:
/** 
 * Waits for any publication requests to finish and closes the   {@link JsonWriter} used foroutput. See class comment for details about  {@code JsonWriter} construction.
 * @param onClosed run after the close() operation has completed asynchronously
 */
private synchronized void close(final Runnable onClosed){
  mExecutor.submit(new Callable<Object>(){
    @Override public Object call() throws Exception {
      try {
        if (mHasWrittenData) {
          mJsonWriter.endArray();
          mHasWrittenData=false;
        }
        mJsonWriter.flush();
        mJsonWriter.close();
        if (DEBUG) {
          Log.d(TAG,"String_Node_Str" + mFile);
        }
      }
 catch (      Exception e) {
        Log.d(TAG,"String_Node_Str",e);
      }
 finally {
        if (mFile != null && mFile.exists()) {
          mFile.setWritable(false,false);
        }
        if (onClosed != null) {
          onClosed.run();
        }
      }
      return null;
    }
  }
);
  removeAnyScheduledFlush();
  mExecutor.shutdown();
}

Fixed version (ground truth):
/** 
 * Waits for any publication requests to finish and closes the   {@link JsonWriter} used foroutput. See class comment for details about  {@code JsonWriter} construction.
 * @param onClosed run after the close() operation has completed asynchronously
 */
private synchronized void close(final Runnable onClosed){
  mExecutor.submit(new Callable<Object>(){
    @Override public Object call() throws Exception {
      try {
        if (!mHasWrittenData) {
          mJsonWriter.beginArray();
        }
        mJsonWriter.endArray();
        mHasWrittenData=false;
        mJsonWriter.flush();
        mJsonWriter.close();
        if (DEBUG) {
          Log.d(TAG,"String_Node_Str" + mFile);
        }
      }
 catch (      Exception e) {
        Log.d(TAG,"String_Node_Str",e);
      }
 finally {
        if (mFile != null && mFile.exists()) {
          mFile.setWritable(false,false);
        }
        if (onClosed != null) {
          onClosed.run();
        }
      }
      return null;
    }
  }
);
  removeAnyScheduledFlush();
  mExecutor.shutdown();
}
Program: 87748
Project: 87748
Buggy source:
@Override public void onDisplayCompletions(final CompletionInfo[] applicationSpecifiedCompletions){
  if (DEBUG) {
    Log.i(TAG,"String_Node_Str");
    if (applicationSpecifiedCompletions != null) {
      for (int i=0; i < applicationSpecifiedCompletions.length; i++) {
        Log.i(TAG,"String_Node_Str" + i + "String_Node_Str"+ applicationSpecifiedCompletions[i]);
      }
    }
  }
  if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn())   return;
  mApplicationSpecifiedCompletions=applicationSpecifiedCompletions;
  if (applicationSpecifiedCompletions == null) {
    clearSuggestionStrip();
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
      ResearchLogger.latinIME_onDisplayCompletions(null);
    }
    return;
  }
  final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords=SuggestedWords.getFromApplicationSpecifiedCompletions(applicationSpecifiedCompletions);
  final SuggestedWords suggestedWords=new SuggestedWords(applicationSuggestedWords,false,false,false,false,false);
  final boolean isAutoCorrection=false;
  setSuggestedWords(suggestedWords,isAutoCorrection);
  setAutoCorrectionIndicator(isAutoCorrection);
  setSuggestionStripShown(true);
  if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
    ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
  }
}

Fixed version (ground truth):
@Override public void onDisplayCompletions(final CompletionInfo[] applicationSpecifiedCompletions){
  if (DEBUG) {
    Log.i(TAG,"String_Node_Str");
    if (applicationSpecifiedCompletions != null) {
      for (int i=0; i < applicationSpecifiedCompletions.length; i++) {
        Log.i(TAG,"String_Node_Str" + i + "String_Node_Str"+ applicationSpecifiedCompletions[i]);
      }
    }
  }
  if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn())   return;
  mApplicationSpecifiedCompletions=CompletionInfoUtils.removeNulls(applicationSpecifiedCompletions);
  if (applicationSpecifiedCompletions == null) {
    clearSuggestionStrip();
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
      ResearchLogger.latinIME_onDisplayCompletions(null);
    }
    return;
  }
  final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords=SuggestedWords.getFromApplicationSpecifiedCompletions(applicationSpecifiedCompletions);
  final SuggestedWords suggestedWords=new SuggestedWords(applicationSuggestedWords,false,false,false,false,false);
  final boolean isAutoCorrection=false;
  setSuggestedWords(suggestedWords,isAutoCorrection);
  setAutoCorrectionIndicator(isAutoCorrection);
  setSuggestionStripShown(true);
  if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
    ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
  }
}
Program: 87749
Project: 87749
Buggy source:
public void commitCompletion(final CompletionInfo completionInfo){
  if (DEBUG_BATCH_NESTING)   checkBatchEdit();
  if (DEBUG_PREVIOUS_TEXT)   checkConsistencyForDebug();
  final CharSequence text=completionInfo.getText();
  mCommittedTextBeforeComposingText.append(text);
  mCurrentCursorPosition+=text.length() - mComposingText.length();
  mComposingText.setLength(0);
  if (null != mIC) {
    mIC.commitCompletion(completionInfo);
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
      ResearchLogger.richInputConnection_commitCompletion(completionInfo);
    }
  }
  if (DEBUG_PREVIOUS_TEXT)   checkConsistencyForDebug();
}

Fixed version (ground truth):
public void commitCompletion(final CompletionInfo completionInfo){
  if (DEBUG_BATCH_NESTING)   checkBatchEdit();
  if (DEBUG_PREVIOUS_TEXT)   checkConsistencyForDebug();
  CharSequence text=completionInfo.getText();
  if (null == text)   text="String_Node_Str";
  mCommittedTextBeforeComposingText.append(text);
  mCurrentCursorPosition+=text.length() - mComposingText.length();
  mComposingText.setLength(0);
  if (null != mIC) {
    mIC.commitCompletion(completionInfo);
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
      ResearchLogger.richInputConnection_commitCompletion(completionInfo);
    }
  }
  if (DEBUG_PREVIOUS_TEXT)   checkConsistencyForDebug();
}
Program: 87750
Project: 87750
Buggy source:
@Override public void onDisplayCompletions(final CompletionInfo[] applicationSpecifiedCompletions){
  if (DEBUG) {
    Log.i(TAG,"String_Node_Str");
    if (applicationSpecifiedCompletions != null) {
      for (int i=0; i < applicationSpecifiedCompletions.length; i++) {
        Log.i(TAG,"String_Node_Str" + i + "String_Node_Str"+ applicationSpecifiedCompletions[i]);
      }
    }
  }
  if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn())   return;
  mApplicationSpecifiedCompletions=applicationSpecifiedCompletions;
  if (applicationSpecifiedCompletions == null) {
    clearSuggestionStrip();
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
      ResearchLogger.latinIME_onDisplayCompletions(null);
    }
    return;
  }
  final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords=SuggestedWords.getFromApplicationSpecifiedCompletions(applicationSpecifiedCompletions);
  final SuggestedWords suggestedWords=new SuggestedWords(applicationSuggestedWords,false,false,false,false,false);
  final boolean isAutoCorrection=false;
  setSuggestedWords(suggestedWords,isAutoCorrection);
  setAutoCorrectionIndicator(isAutoCorrection);
  setSuggestionStripShown(true);
  if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
    ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
  }
}

Fixed version (ground truth):
@Override public void onDisplayCompletions(final CompletionInfo[] applicationSpecifiedCompletions){
  if (DEBUG) {
    Log.i(TAG,"String_Node_Str");
    if (applicationSpecifiedCompletions != null) {
      for (int i=0; i < applicationSpecifiedCompletions.length; i++) {
        Log.i(TAG,"String_Node_Str" + i + "String_Node_Str"+ applicationSpecifiedCompletions[i]);
      }
    }
  }
  if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn())   return;
  mApplicationSpecifiedCompletions=CompletionInfoUtils.removeNulls(applicationSpecifiedCompletions);
  if (applicationSpecifiedCompletions == null) {
    clearSuggestionStrip();
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
      ResearchLogger.latinIME_onDisplayCompletions(null);
    }
    return;
  }
  final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords=SuggestedWords.getFromApplicationSpecifiedCompletions(applicationSpecifiedCompletions);
  final SuggestedWords suggestedWords=new SuggestedWords(applicationSuggestedWords,false,false,false,false,false);
  final boolean isAutoCorrection=false;
  setSuggestedWords(suggestedWords,isAutoCorrection);
  setAutoCorrectionIndicator(isAutoCorrection);
  setSuggestionStripShown(true);
  if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
    ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
  }
}
Program: 87751
Project: 87751
Buggy source:
public void commitCompletion(final CompletionInfo completionInfo){
  if (DEBUG_BATCH_NESTING)   checkBatchEdit();
  if (DEBUG_PREVIOUS_TEXT)   checkConsistencyForDebug();
  final CharSequence text=completionInfo.getText();
  mCommittedTextBeforeComposingText.append(text);
  mCurrentCursorPosition+=text.length() - mComposingText.length();
  mComposingText.setLength(0);
  if (null != mIC) {
    mIC.commitCompletion(completionInfo);
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
      ResearchLogger.richInputConnection_commitCompletion(completionInfo);
    }
  }
  if (DEBUG_PREVIOUS_TEXT)   checkConsistencyForDebug();
}

Fixed version (ground truth):
public void commitCompletion(final CompletionInfo completionInfo){
  if (DEBUG_BATCH_NESTING)   checkBatchEdit();
  if (DEBUG_PREVIOUS_TEXT)   checkConsistencyForDebug();
  CharSequence text=completionInfo.getText();
  if (null == text)   text="String_Node_Str";
  mCommittedTextBeforeComposingText.append(text);
  mCurrentCursorPosition+=text.length() - mComposingText.length();
  mComposingText.setLength(0);
  if (null != mIC) {
    mIC.commitCompletion(completionInfo);
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
      ResearchLogger.richInputConnection_commitCompletion(completionInfo);
    }
  }
  if (DEBUG_PREVIOUS_TEXT)   checkConsistencyForDebug();
}
Program: 87752
Project: 87752
Buggy source:
@Override public Word next(){
  Position currentPos=mPositions.getLast();
  mCurrentString.setLength(currentPos.length);
  do {
    if (currentPos.pos.hasNext()) {
      final CharGroup currentGroup=currentPos.pos.next();
      currentPos.length=mCurrentString.length();
      for (      int i : currentGroup.mChars)       mCurrentString.append(Character.toChars(i));
      if (null != currentGroup.mChildren) {
        currentPos=new Position(currentGroup.mChildren.mData);
        mPositions.addLast(currentPos);
      }
      if (currentGroup.mFrequency >= 0)       return new Word(mCurrentString.toString(),currentGroup.mFrequency,currentGroup.mShortcutTargets,currentGroup.mBigrams,currentGroup.mIsNotAWord,currentGroup.mIsBlacklistEntry);
    }
 else {
      mPositions.removeLast();
      currentPos=mPositions.getLast();
      mCurrentString.setLength(mPositions.getLast().length);
    }
  }
 while (true);
}

Fixed version (ground truth):
@Override public Word next(){
  Position currentPos=mPositions.getLast();
  mCurrentString.setLength(currentPos.length);
  do {
    if (currentPos.pos.hasNext()) {
      final CharGroup currentGroup=currentPos.pos.next();
      currentPos.length=mCurrentString.length();
      for (      int i : currentGroup.mChars) {
        mCurrentString.append(Character.toChars(i));
      }
      if (null != currentGroup.mChildren) {
        currentPos=new Position(currentGroup.mChildren.mData);
        currentPos.length=mCurrentString.length();
        mPositions.addLast(currentPos);
      }
      if (currentGroup.mFrequency >= 0) {
        return new Word(mCurrentString.toString(),currentGroup.mFrequency,currentGroup.mShortcutTargets,currentGroup.mBigrams,currentGroup.mIsNotAWord,currentGroup.mIsBlacklistEntry);
      }
    }
 else {
      mPositions.removeLast();
      currentPos=mPositions.getLast();
      mCurrentString.setLength(mPositions.getLast().length);
    }
  }
 while (true);
}
Program: 87753
Project: 87753
Buggy source:
/** 
 * Helper method to find a word in a given branch.
 */
@SuppressWarnings("String_Node_Str") public static CharGroup findWordInTree(Node node,final String string){
  int index=0;
  final StringBuilder checker=DBG ? new StringBuilder() : null;
  final int[] codePoints=getCodePoints(string);
  CharGroup currentGroup;
  do {
    int indexOfGroup=findIndexOfChar(node,codePoints[index]);
    if (CHARACTER_NOT_FOUND == indexOfGroup)     return null;
    currentGroup=node.mData.get(indexOfGroup);
    if (codePoints.length - index < currentGroup.mChars.length)     return null;
    int newIndex=index;
    while (newIndex < codePoints.length && newIndex - index < currentGroup.mChars.length) {
      if (currentGroup.mChars[newIndex - index] != codePoints[newIndex])       return null;
      newIndex++;
    }
    index=newIndex;
    if (DBG)     checker.append(new String(currentGroup.mChars,0,currentGroup.mChars.length));
    if (index < codePoints.length) {
      node=currentGroup.mChildren;
    }
  }
 while (null != node && index < codePoints.length);
  if (index < codePoints.length)   return null;
  if (!currentGroup.isTerminal())   return null;
  if (DBG && !codePoints.equals(checker.toString()))   return null;
  return currentGroup;
}

Fixed version (ground truth):
/** 
 * Helper method to find a word in a given branch.
 */
@SuppressWarnings("String_Node_Str") public static CharGroup findWordInTree(Node node,final String string){
  int index=0;
  final StringBuilder checker=DBG ? new StringBuilder() : null;
  final int[] codePoints=getCodePoints(string);
  CharGroup currentGroup;
  do {
    int indexOfGroup=findIndexOfChar(node,codePoints[index]);
    if (CHARACTER_NOT_FOUND == indexOfGroup)     return null;
    currentGroup=node.mData.get(indexOfGroup);
    if (codePoints.length - index < currentGroup.mChars.length)     return null;
    int newIndex=index;
    while (newIndex < codePoints.length && newIndex - index < currentGroup.mChars.length) {
      if (currentGroup.mChars[newIndex - index] != codePoints[newIndex])       return null;
      newIndex++;
    }
    index=newIndex;
    if (DBG)     checker.append(new String(currentGroup.mChars,0,currentGroup.mChars.length));
    if (index < codePoints.length) {
      node=currentGroup.mChildren;
    }
  }
 while (null != node && index < codePoints.length);
  if (index < codePoints.length)   return null;
  if (!currentGroup.isTerminal())   return null;
  if (DBG && !string.equals(checker.toString()))   return null;
  return currentGroup;
}
Program: 87754
Project: 87754
Buggy source:
@Override public Word next(){
  Position currentPos=mPositions.getLast();
  mCurrentString.setLength(currentPos.length);
  do {
    if (currentPos.pos.hasNext()) {
      final CharGroup currentGroup=currentPos.pos.next();
      currentPos.length=mCurrentString.length();
      for (      int i : currentGroup.mChars)       mCurrentString.append(Character.toChars(i));
      if (null != currentGroup.mChildren) {
        currentPos=new Position(currentGroup.mChildren.mData);
        mPositions.addLast(currentPos);
      }
      if (currentGroup.mFrequency >= 0)       return new Word(mCurrentString.toString(),currentGroup.mFrequency,currentGroup.mShortcutTargets,currentGroup.mBigrams,currentGroup.mIsNotAWord,currentGroup.mIsBlacklistEntry);
    }
 else {
      mPositions.removeLast();
      currentPos=mPositions.getLast();
      mCurrentString.setLength(mPositions.getLast().length);
    }
  }
 while (true);
}

Fixed version (ground truth):
@Override public Word next(){
  Position currentPos=mPositions.getLast();
  mCurrentString.setLength(currentPos.length);
  do {
    if (currentPos.pos.hasNext()) {
      final CharGroup currentGroup=currentPos.pos.next();
      currentPos.length=mCurrentString.length();
      for (      int i : currentGroup.mChars) {
        mCurrentString.append(Character.toChars(i));
      }
      if (null != currentGroup.mChildren) {
        currentPos=new Position(currentGroup.mChildren.mData);
        currentPos.length=mCurrentString.length();
        mPositions.addLast(currentPos);
      }
      if (currentGroup.mFrequency >= 0) {
        return new Word(mCurrentString.toString(),currentGroup.mFrequency,currentGroup.mShortcutTargets,currentGroup.mBigrams,currentGroup.mIsNotAWord,currentGroup.mIsBlacklistEntry);
      }
    }
 else {
      mPositions.removeLast();
      currentPos=mPositions.getLast();
      mCurrentString.setLength(mPositions.getLast().length);
    }
  }
 while (true);
}
Program: 87755
Project: 87755
Buggy source:
/** 
 * Helper method to find a word in a given branch.
 */
@SuppressWarnings("String_Node_Str") public static CharGroup findWordInTree(Node node,final String string){
  int index=0;
  final StringBuilder checker=DBG ? new StringBuilder() : null;
  final int[] codePoints=getCodePoints(string);
  CharGroup currentGroup;
  do {
    int indexOfGroup=findIndexOfChar(node,codePoints[index]);
    if (CHARACTER_NOT_FOUND == indexOfGroup)     return null;
    currentGroup=node.mData.get(indexOfGroup);
    if (codePoints.length - index < currentGroup.mChars.length)     return null;
    int newIndex=index;
    while (newIndex < codePoints.length && newIndex - index < currentGroup.mChars.length) {
      if (currentGroup.mChars[newIndex - index] != codePoints[newIndex])       return null;
      newIndex++;
    }
    index=newIndex;
    if (DBG)     checker.append(new String(currentGroup.mChars,0,currentGroup.mChars.length));
    if (index < codePoints.length) {
      node=currentGroup.mChildren;
    }
  }
 while (null != node && index < codePoints.length);
  if (index < codePoints.length)   return null;
  if (!currentGroup.isTerminal())   return null;
  if (DBG && !codePoints.equals(checker.toString()))   return null;
  return currentGroup;
}

Fixed version (ground truth):
/** 
 * Helper method to find a word in a given branch.
 */
@SuppressWarnings("String_Node_Str") public static CharGroup findWordInTree(Node node,final String string){
  int index=0;
  final StringBuilder checker=DBG ? new StringBuilder() : null;
  final int[] codePoints=getCodePoints(string);
  CharGroup currentGroup;
  do {
    int indexOfGroup=findIndexOfChar(node,codePoints[index]);
    if (CHARACTER_NOT_FOUND == indexOfGroup)     return null;
    currentGroup=node.mData.get(indexOfGroup);
    if (codePoints.length - index < currentGroup.mChars.length)     return null;
    int newIndex=index;
    while (newIndex < codePoints.length && newIndex - index < currentGroup.mChars.length) {
      if (currentGroup.mChars[newIndex - index] != codePoints[newIndex])       return null;
      newIndex++;
    }
    index=newIndex;
    if (DBG)     checker.append(new String(currentGroup.mChars,0,currentGroup.mChars.length));
    if (index < codePoints.length) {
      node=currentGroup.mChildren;
    }
  }
 while (null != node && index < codePoints.length);
  if (index < codePoints.length)   return null;
  if (!currentGroup.isTerminal())   return null;
  if (DBG && !string.equals(checker.toString()))   return null;
  return currentGroup;
}
Program: 87756
Project: 87756
Buggy source:
public static int getCapitalizationType(final String text){
  if (!Character.isUpperCase(text.codePointAt(0)))   return CAPITALIZE_NONE;
  final int len=text.length();
  int capsCount=1;
  int letterCount=1;
  for (int i=1; i < len; i=text.offsetByCodePoints(i,1)) {
    if (1 != capsCount && letterCount != capsCount)     break;
    final int codePoint=text.codePointAt(i);
    if (Character.isUpperCase(codePoint)) {
      ++capsCount;
      ++letterCount;
    }
 else     if (Character.isLetter(codePoint)) {
      ++letterCount;
    }
  }
  if (1 == capsCount)   return CAPITALIZE_FIRST;
  return (letterCount == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE);
}

Fixed version (ground truth):
public static int getCapitalizationType(final String text){
  final int len=text.length();
  int index=0;
  for (; index < len; index=text.offsetByCodePoints(index,1)) {
    if (Character.isLetter(text.codePointAt(index))) {
      break;
    }
  }
  if (index == len)   return CAPITALIZE_NONE;
  if (!Character.isUpperCase(text.codePointAt(index))) {
    return CAPITALIZE_NONE;
  }
  int capsCount=1;
  int letterCount=1;
  for (index=text.offsetByCodePoints(index,1); index < len; index=text.offsetByCodePoints(index,1)) {
    if (1 != capsCount && letterCount != capsCount)     break;
    final int codePoint=text.codePointAt(index);
    if (Character.isUpperCase(codePoint)) {
      ++capsCount;
      ++letterCount;
    }
 else     if (Character.isLetter(codePoint)) {
      ++letterCount;
    }
  }
  if (1 == capsCount)   return CAPITALIZE_FIRST;
  return (letterCount == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE);
}
Program: 87757
Project: 87757
Buggy source:
public static String toTitleCase(final String s,final Locale locale){
  if (s.length() <= 1) {
    return s;
  }
  return s.toUpperCase(locale).charAt(0) + s.substring(1);
}

Fixed version (ground truth):
public static String toTitleCase(final String s,final Locale locale){
  if (s.length() <= 1) {
    return s;
  }
  final int cutoff=s.offsetByCodePoints(0,1);
  return s.substring(0,cutoff).toUpperCase(locale) + s.substring(cutoff).toLowerCase(locale);
}
Program: 87758
Project: 87758
Buggy source:
@Override public Word next(){
  Position currentPos=mPositions.getLast();
  mCurrentString.setLength(currentPos.length);
  do {
    if (currentPos.pos.hasNext()) {
      final CharGroup currentGroup=currentPos.pos.next();
      currentPos.length=mCurrentString.length();
      for (      int i : currentGroup.mChars)       mCurrentString.append(Character.toChars(i));
      if (null != currentGroup.mChildren) {
        currentPos=new Position(currentGroup.mChildren.mData);
        mPositions.addLast(currentPos);
      }
      if (currentGroup.mFrequency >= 0)       return new Word(mCurrentString.toString(),currentGroup.mFrequency,currentGroup.mShortcutTargets,currentGroup.mBigrams,currentGroup.mIsNotAWord,currentGroup.mIsBlacklistEntry);
    }
 else {
      mPositions.removeLast();
      currentPos=mPositions.getLast();
      mCurrentString.setLength(mPositions.getLast().length);
    }
  }
 while (true);
}

Fixed version (ground truth):
@Override public Word next(){
  Position currentPos=mPositions.getLast();
  mCurrentString.setLength(currentPos.length);
  do {
    if (currentPos.pos.hasNext()) {
      final CharGroup currentGroup=currentPos.pos.next();
      currentPos.length=mCurrentString.length();
      for (      int i : currentGroup.mChars) {
        mCurrentString.append(Character.toChars(i));
      }
      if (null != currentGroup.mChildren) {
        currentPos=new Position(currentGroup.mChildren.mData);
        currentPos.length=mCurrentString.length();
        mPositions.addLast(currentPos);
      }
      if (currentGroup.mFrequency >= 0) {
        return new Word(mCurrentString.toString(),currentGroup.mFrequency,currentGroup.mShortcutTargets,currentGroup.mBigrams,currentGroup.mIsNotAWord,currentGroup.mIsBlacklistEntry);
      }
    }
 else {
      mPositions.removeLast();
      currentPos=mPositions.getLast();
      mCurrentString.setLength(mPositions.getLast().length);
    }
  }
 while (true);
}
Program: 87759
Project: 87759
Buggy source:
/** 
 * Helper method to find a word in a given branch.
 */
@SuppressWarnings("String_Node_Str") public static CharGroup findWordInTree(Node node,final String string){
  int index=0;
  final StringBuilder checker=DBG ? new StringBuilder() : null;
  final int[] codePoints=getCodePoints(string);
  CharGroup currentGroup;
  do {
    int indexOfGroup=findIndexOfChar(node,codePoints[index]);
    if (CHARACTER_NOT_FOUND == indexOfGroup)     return null;
    currentGroup=node.mData.get(indexOfGroup);
    if (codePoints.length - index < currentGroup.mChars.length)     return null;
    int newIndex=index;
    while (newIndex < codePoints.length && newIndex - index < currentGroup.mChars.length) {
      if (currentGroup.mChars[newIndex - index] != codePoints[newIndex])       return null;
      newIndex++;
    }
    index=newIndex;
    if (DBG)     checker.append(new String(currentGroup.mChars,0,currentGroup.mChars.length));
    if (index < codePoints.length) {
      node=currentGroup.mChildren;
    }
  }
 while (null != node && index < codePoints.length);
  if (index < codePoints.length)   return null;
  if (!currentGroup.isTerminal())   return null;
  if (DBG && !codePoints.equals(checker.toString()))   return null;
  return currentGroup;
}

Fixed version (ground truth):
/** 
 * Helper method to find a word in a given branch.
 */
@SuppressWarnings("String_Node_Str") public static CharGroup findWordInTree(Node node,final String string){
  int index=0;
  final StringBuilder checker=DBG ? new StringBuilder() : null;
  final int[] codePoints=getCodePoints(string);
  CharGroup currentGroup;
  do {
    int indexOfGroup=findIndexOfChar(node,codePoints[index]);
    if (CHARACTER_NOT_FOUND == indexOfGroup)     return null;
    currentGroup=node.mData.get(indexOfGroup);
    if (codePoints.length - index < currentGroup.mChars.length)     return null;
    int newIndex=index;
    while (newIndex < codePoints.length && newIndex - index < currentGroup.mChars.length) {
      if (currentGroup.mChars[newIndex - index] != codePoints[newIndex])       return null;
      newIndex++;
    }
    index=newIndex;
    if (DBG)     checker.append(new String(currentGroup.mChars,0,currentGroup.mChars.length));
    if (index < codePoints.length) {
      node=currentGroup.mChildren;
    }
  }
 while (null != node && index < codePoints.length);
  if (index < codePoints.length)   return null;
  if (!currentGroup.isTerminal())   return null;
  if (DBG && !string.equals(checker.toString()))   return null;
  return currentGroup;
}
Program: 87760
Project: 87760
Buggy source:
public static int getCapitalizationType(final String text){
  if (!Character.isUpperCase(text.codePointAt(0)))   return CAPITALIZE_NONE;
  final int len=text.length();
  int capsCount=1;
  int letterCount=1;
  for (int i=1; i < len; i=text.offsetByCodePoints(i,1)) {
    if (1 != capsCount && letterCount != capsCount)     break;
    final int codePoint=text.codePointAt(i);
    if (Character.isUpperCase(codePoint)) {
      ++capsCount;
      ++letterCount;
    }
 else     if (Character.isLetter(codePoint)) {
      ++letterCount;
    }
  }
  if (1 == capsCount)   return CAPITALIZE_FIRST;
  return (letterCount == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE);
}

Fixed version (ground truth):
public static int getCapitalizationType(final String text){
  final int len=text.length();
  int index=0;
  for (; index < len; index=text.offsetByCodePoints(index,1)) {
    if (Character.isLetter(text.codePointAt(index))) {
      break;
    }
  }
  if (index == len)   return CAPITALIZE_NONE;
  if (!Character.isUpperCase(text.codePointAt(index))) {
    return CAPITALIZE_NONE;
  }
  int capsCount=1;
  int letterCount=1;
  for (index=text.offsetByCodePoints(index,1); index < len; index=text.offsetByCodePoints(index,1)) {
    if (1 != capsCount && letterCount != capsCount)     break;
    final int codePoint=text.codePointAt(index);
    if (Character.isUpperCase(codePoint)) {
      ++capsCount;
      ++letterCount;
    }
 else     if (Character.isLetter(codePoint)) {
      ++letterCount;
    }
  }
  if (1 == capsCount)   return CAPITALIZE_FIRST;
  return (letterCount == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE);
}
Program: 87761
Project: 87761
Buggy source:
public static String toTitleCase(final String s,final Locale locale){
  if (s.length() <= 1) {
    return s;
  }
  return s.toUpperCase(locale).charAt(0) + s.substring(1);
}

Fixed version (ground truth):
public static String toTitleCase(final String s,final Locale locale){
  if (s.length() <= 1) {
    return s;
  }
  final int cutoff=s.offsetByCodePoints(0,1);
  return s.substring(0,cutoff).toUpperCase(locale) + s.substring(cutoff).toLowerCase(locale);
}
Program: 87762
Project: 87762
Buggy source:
static String getShortDisplayName(final InputMethodSubtype subtype){
  if (SubtypeLocale.isNoLanguage(subtype)) {
    return "String_Node_Str";
  }
  final Locale locale=SubtypeLocale.getSubtypeLocale(subtype);
  return StringUtils.capitalizeFirstCharacter(locale.getLanguage(),locale);
}

Fixed version (ground truth):
static String getShortDisplayName(final InputMethodSubtype subtype){
  if (SubtypeLocale.isNoLanguage(subtype)) {
    return "String_Node_Str";
  }
  final Locale locale=SubtypeLocale.getSubtypeLocale(subtype);
  return StringUtils.capitalizeFirstCodePoint(locale.getLanguage(),locale);
}
Program: 87763
Project: 87763
Buggy source:
/** 
 * Apply an auto-caps mode to a string. This intentionally does NOT apply manual caps mode. It only changes the capitalization if the mode is one of the auto-caps modes.
 * @param s The string to capitalize.
 * @param capitalizeMode The mode in which to capitalize.
 * @param locale The locale for capitalizing.
 * @return The capitalized string.
 */
public static String applyAutoCapsMode(final String s,final int capitalizeMode,final Locale locale){
  if (WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED == capitalizeMode) {
    return s.toUpperCase(locale);
  }
 else   if (WordComposer.CAPS_MODE_AUTO_SHIFTED == capitalizeMode) {
    return StringUtils.toTitleCase(s,locale);
  }
 else {
    return s;
  }
}

Fixed version (ground truth):
/** 
 * Apply an auto-caps mode to a string. This intentionally does NOT apply manual caps mode. It only changes the capitalization if the mode is one of the auto-caps modes.
 * @param s The string to capitalize.
 * @param capitalizeMode The mode in which to capitalize.
 * @param locale The locale for capitalizing.
 * @return The capitalized string.
 */
public static String applyAutoCapsMode(final String s,final int capitalizeMode,final Locale locale){
  if (WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED == capitalizeMode) {
    return s.toUpperCase(locale);
  }
 else   if (WordComposer.CAPS_MODE_AUTO_SHIFTED == capitalizeMode) {
    return StringUtils.capitalizeFirstCodePoint(s,locale);
  }
 else {
    return s;
  }
}
Program: 87764
Project: 87764
Buggy source:
private static String getSubtypeDisplayNameInternal(final InputMethodSubtype subtype,final Locale displayLocale){
  final String replacementString=getReplacementString(subtype,displayLocale);
  final int nameResId=subtype.getNameResId();
  final RunInLocale<String> getSubtypeName=new RunInLocale<String>(){
    @Override protected String job(    final Resources res){
      try {
        return res.getString(nameResId,replacementString);
      }
 catch (      Resources.NotFoundException e) {
        Log.w(TAG,"String_Node_Str" + subtype.getMode() + "String_Node_Str"+ subtype.getNameResId()+ "String_Node_Str"+ subtype.getLocale()+ "String_Node_Str"+ subtype.getExtraValue()+ "String_Node_Str"+ Utils.getStackTrace());
        return "String_Node_Str";
      }
    }
  }
;
  return StringUtils.capitalizeFirstCharacter(getSubtypeName.runInLocale(sResources,displayLocale),displayLocale);
}

Fixed version (ground truth):
private static String getSubtypeDisplayNameInternal(final InputMethodSubtype subtype,final Locale displayLocale){
  final String replacementString=getReplacementString(subtype,displayLocale);
  final int nameResId=subtype.getNameResId();
  final RunInLocale<String> getSubtypeName=new RunInLocale<String>(){
    @Override protected String job(    final Resources res){
      try {
        return res.getString(nameResId,replacementString);
      }
 catch (      Resources.NotFoundException e) {
        Log.w(TAG,"String_Node_Str" + subtype.getMode() + "String_Node_Str"+ subtype.getNameResId()+ "String_Node_Str"+ subtype.getLocale()+ "String_Node_Str"+ subtype.getExtraValue()+ "String_Node_Str"+ Utils.getStackTrace());
        return "String_Node_Str";
      }
    }
  }
;
  return StringUtils.capitalizeFirstCodePoint(getSubtypeName.runInLocale(sResources,displayLocale),displayLocale);
}
Program: 87765
Project: 87765
Buggy source:
private static String getSubtypeLocaleDisplayNameInternal(final String localeString,final Locale displayLocale){
  final Integer exceptionalNameResId=sExceptionalLocaleToNameIdsMap.get(localeString);
  final String displayName;
  if (exceptionalNameResId != null) {
    final RunInLocale<String> getExceptionalName=new RunInLocale<String>(){
      @Override protected String job(      final Resources res){
        return res.getString(exceptionalNameResId);
      }
    }
;
    displayName=getExceptionalName.runInLocale(sResources,displayLocale);
  }
 else   if (NO_LANGUAGE.equals(localeString)) {
    return sResources.getString(R.string.subtype_no_language);
  }
 else {
    final Locale locale=LocaleUtils.constructLocaleFromString(localeString);
    displayName=locale.getDisplayName(displayLocale);
  }
  return StringUtils.capitalizeFirstCharacter(displayName,displayLocale);
}

Fixed version (ground truth):
private static String getSubtypeLocaleDisplayNameInternal(final String localeString,final Locale displayLocale){
  final Integer exceptionalNameResId=sExceptionalLocaleToNameIdsMap.get(localeString);
  final String displayName;
  if (exceptionalNameResId != null) {
    final RunInLocale<String> getExceptionalName=new RunInLocale<String>(){
      @Override protected String job(      final Resources res){
        return res.getString(exceptionalNameResId);
      }
    }
;
    displayName=getExceptionalName.runInLocale(sResources,displayLocale);
  }
 else   if (NO_LANGUAGE.equals(localeString)) {
    return sResources.getString(R.string.subtype_no_language);
  }
 else {
    final Locale locale=LocaleUtils.constructLocaleFromString(localeString);
    displayName=locale.getDisplayName(displayLocale);
  }
  return StringUtils.capitalizeFirstCodePoint(displayName,displayLocale);
}
Program: 87766
Project: 87766
Buggy source:
private static SuggestedWordInfo getTransformedSuggestedWordInfo(final SuggestedWordInfo wordInfo,final Locale locale,final boolean isAllUpperCase,final boolean isFirstCharCapitalized,final int trailingSingleQuotesCount){
  final StringBuilder sb=new StringBuilder(wordInfo.mWord.length());
  if (isAllUpperCase) {
    sb.append(wordInfo.mWord.toUpperCase(locale));
  }
 else   if (isFirstCharCapitalized) {
    sb.append(StringUtils.toTitleCase(wordInfo.mWord,locale));
  }
 else {
    sb.append(wordInfo.mWord);
  }
  for (int i=trailingSingleQuotesCount - 1; i >= 0; --i) {
    sb.appendCodePoint(Constants.CODE_SINGLE_QUOTE);
  }
  return new SuggestedWordInfo(sb.toString(),wordInfo.mScore,wordInfo.mKind,wordInfo.mSourceDict);
}

Fixed version (ground truth):
private static SuggestedWordInfo getTransformedSuggestedWordInfo(final SuggestedWordInfo wordInfo,final Locale locale,final boolean isAllUpperCase,final boolean isFirstCharCapitalized,final int trailingSingleQuotesCount){
  final StringBuilder sb=new StringBuilder(wordInfo.mWord.length());
  if (isAllUpperCase) {
    sb.append(wordInfo.mWord.toUpperCase(locale));
  }
 else   if (isFirstCharCapitalized) {
    sb.append(StringUtils.capitalizeFirstCodePoint(wordInfo.mWord,locale));
  }
 else {
    sb.append(wordInfo.mWord);
  }
  for (int i=trailingSingleQuotesCount - 1; i >= 0; --i) {
    sb.appendCodePoint(Constants.CODE_SINGLE_QUOTE);
  }
  return new SuggestedWordInfo(sb.toString(),wordInfo.mScore,wordInfo.mKind,wordInfo.mSourceDict);
}
Program: 87768
Project: 87768
Buggy source:
/** 
 * Helper method to test valid capitalizations of a word. If the "text" is lower-case, we test only the exact string. If the "Text" is capitalized, we test the exact string "Text" and the lower-cased version of it "text". If the "TEXT" is fully upper case, we test the exact string "TEXT", the lower-cased version of it "text" and the capitalized version of it "Text".
 */
private boolean isInDictForAnyCapitalization(final Dictionary dict,final String text,final int capitalizeType){
  if (dict.isValidWord(text))   return true;
  if (StringUtils.CAPITALIZE_NONE == capitalizeType)   return false;
  final String lowerCaseText=text.toLowerCase(mLocale);
  if (dict.isValidWord(lowerCaseText))   return true;
  if (StringUtils.CAPITALIZE_FIRST == capitalizeType)   return false;
  return dict.isValidWord(StringUtils.toTitleCase(lowerCaseText,mLocale));
}

Fixed version (ground truth):
/** 
 * Helper method to test valid capitalizations of a word. If the "text" is lower-case, we test only the exact string. If the "Text" is capitalized, we test the exact string "Text" and the lower-cased version of it "text". If the "TEXT" is fully upper case, we test the exact string "TEXT", the lower-cased version of it "text" and the capitalized version of it "Text".
 */
private boolean isInDictForAnyCapitalization(final Dictionary dict,final String text,final int capitalizeType){
  if (dict.isValidWord(text))   return true;
  if (StringUtils.CAPITALIZE_NONE == capitalizeType)   return false;
  final String lowerCaseText=text.toLowerCase(mLocale);
  if (dict.isValidWord(lowerCaseText))   return true;
  if (StringUtils.CAPITALIZE_FIRST == capitalizeType)   return false;
  return dict.isValidWord(StringUtils.capitalizeFirstAndDowncaseRest(lowerCaseText,mLocale));
}
Program: 87769
Project: 87769
Buggy source:
public void testAllShortDisplayName(){
  for (  final InputMethodSubtype subtype : mSubtypesList) {
    final String subtypeName=SubtypeLocale.getSubtypeDisplayName(subtype);
    final Locale locale=SubtypeLocale.getSubtypeLocale(subtype);
    final String spacebarText=MainKeyboardView.getShortDisplayName(subtype);
    final String languageCode=StringUtils.capitalizeFirstCharacter(locale.getLanguage(),locale);
    if (SubtypeLocale.isNoLanguage(subtype)) {
      assertEquals(subtypeName,"String_Node_Str",spacebarText);
    }
 else {
      assertEquals(subtypeName,languageCode,spacebarText);
    }
  }
}

Fixed version (ground truth):
public void testAllShortDisplayName(){
  for (  final InputMethodSubtype subtype : mSubtypesList) {
    final String subtypeName=SubtypeLocale.getSubtypeDisplayName(subtype);
    final Locale locale=SubtypeLocale.getSubtypeLocale(subtype);
    final String spacebarText=MainKeyboardView.getShortDisplayName(subtype);
    final String languageCode=StringUtils.capitalizeFirstCodePoint(locale.getLanguage(),locale);
    if (SubtypeLocale.isNoLanguage(subtype)) {
      assertEquals(subtypeName,"String_Node_Str",spacebarText);
    }
 else {
      assertEquals(subtypeName,languageCode,spacebarText);
    }
  }
}
Program: 87770
Project: 87770
Buggy source:
public static int getCapitalizationType(final String text){
  if (!Character.isUpperCase(text.codePointAt(0)))   return CAPITALIZE_NONE;
  final int len=text.length();
  int capsCount=1;
  int letterCount=1;
  for (int i=1; i < len; i=text.offsetByCodePoints(i,1)) {
    if (1 != capsCount && letterCount != capsCount)     break;
    final int codePoint=text.codePointAt(i);
    if (Character.isUpperCase(codePoint)) {
      ++capsCount;
      ++letterCount;
    }
 else     if (Character.isLetter(codePoint)) {
      ++letterCount;
    }
  }
  if (1 == capsCount)   return CAPITALIZE_FIRST;
  return (letterCount == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE);
}

Fixed version (ground truth):
public static int getCapitalizationType(final String text){
  final int len=text.length();
  int index=0;
  for (; index < len; index=text.offsetByCodePoints(index,1)) {
    if (Character.isLetter(text.codePointAt(index))) {
      break;
    }
  }
  if (index == len)   return CAPITALIZE_NONE;
  if (!Character.isUpperCase(text.codePointAt(index))) {
    return CAPITALIZE_NONE;
  }
  int capsCount=1;
  int letterCount=1;
  for (index=text.offsetByCodePoints(index,1); index < len; index=text.offsetByCodePoints(index,1)) {
    if (1 != capsCount && letterCount != capsCount)     break;
    final int codePoint=text.codePointAt(index);
    if (Character.isUpperCase(codePoint)) {
      ++capsCount;
      ++letterCount;
    }
 else     if (Character.isLetter(codePoint)) {
      ++letterCount;
    }
  }
  if (1 == capsCount)   return CAPITALIZE_FIRST;
  return (letterCount == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE);
}
Program: 87771
Project: 87771
Buggy source:
public static String toTitleCase(final String s,final Locale locale){
  if (s.length() <= 1) {
    return s;
  }
  return s.toUpperCase(locale).charAt(0) + s.substring(1);
}

Fixed version (ground truth):
public static String toTitleCase(final String s,final Locale locale){
  if (s.length() <= 1) {
    return s;
  }
  final int cutoff=s.offsetByCodePoints(0,1);
  return s.substring(0,cutoff).toUpperCase(locale) + s.substring(cutoff).toLowerCase(locale);
}
Program: 87772
Project: 87772
Buggy source:
static String getShortDisplayName(final InputMethodSubtype subtype){
  if (SubtypeLocale.isNoLanguage(subtype)) {
    return "String_Node_Str";
  }
  final Locale locale=SubtypeLocale.getSubtypeLocale(subtype);
  return StringUtils.capitalizeFirstCharacter(locale.getLanguage(),locale);
}

Fixed version (ground truth):
static String getShortDisplayName(final InputMethodSubtype subtype){
  if (SubtypeLocale.isNoLanguage(subtype)) {
    return "String_Node_Str";
  }
  final Locale locale=SubtypeLocale.getSubtypeLocale(subtype);
  return StringUtils.capitalizeFirstCodePoint(locale.getLanguage(),locale);
}