Program: 182023
Project: 182023
Buggy source:
/** 
 * Perform clear operation as requested by  {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the stack to the given task, then look for an instance of that activity in the stack and, if found, finish all activities on top of it and return the instance.
 * @param newR Description of the new activity being started.
 * @return Returns the old activity that should be continue to be used,or null if none was found.
 */
private final HistoryRecord performClearTaskLocked(int taskId,HistoryRecord newR,int launchFlags,boolean doClear){
  int i=mHistory.size();
  while (i > 0) {
    i--;
    HistoryRecord r=(HistoryRecord)mHistory.get(i);
    if (r.task.taskId == taskId) {
      i++;
      break;
    }
  }
  while (i > 0) {
    i--;
    HistoryRecord r=(HistoryRecord)mHistory.get(i);
    if (r.finishing) {
      continue;
    }
    if (r.task.taskId != taskId) {
      return null;
    }
    if (r.realActivity.equals(newR.realActivity)) {
      HistoryRecord ret=r;
      if (doClear) {
        while (i < (mHistory.size() - 1)) {
          i++;
          r=(HistoryRecord)mHistory.get(i);
          if (r.finishing) {
            continue;
          }
          if (finishActivityLocked(r,i,Activity.RESULT_CANCELED,null,"String_Node_Str")) {
            i--;
          }
        }
      }
      if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
        if (!ret.finishing) {
          int index=indexOfTokenLocked(ret);
          if (index >= 0) {
            finishActivityLocked(ret,0,Activity.RESULT_CANCELED,null,"String_Node_Str");
          }
          return null;
        }
      }
      return ret;
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Perform clear operation as requested by  {@link Intent#FLAG_ACTIVITY_CLEAR_TOP}: search from the top of the stack to the given task, then look for an instance of that activity in the stack and, if found, finish all activities on top of it and return the instance.
 * @param newR Description of the new activity being started.
 * @return Returns the old activity that should be continue to be used,or null if none was found.
 */
private final HistoryRecord performClearTaskLocked(int taskId,HistoryRecord newR,int launchFlags,boolean doClear){
  int i=mHistory.size();
  while (i > 0) {
    i--;
    HistoryRecord r=(HistoryRecord)mHistory.get(i);
    if (r.task.taskId == taskId) {
      i++;
      break;
    }
  }
  while (i > 0) {
    i--;
    HistoryRecord r=(HistoryRecord)mHistory.get(i);
    if (r.finishing) {
      continue;
    }
    if (r.task.taskId != taskId) {
      return null;
    }
    if (r.realActivity.equals(newR.realActivity)) {
      HistoryRecord ret=r;
      if (doClear) {
        while (i < (mHistory.size() - 1)) {
          i++;
          r=(HistoryRecord)mHistory.get(i);
          if (r.finishing) {
            continue;
          }
          if (finishActivityLocked(r,i,Activity.RESULT_CANCELED,null,"String_Node_Str")) {
            i--;
          }
        }
      }
      if (ret.launchMode == ActivityInfo.LAUNCH_MULTIPLE && (launchFlags & Intent.FLAG_ACTIVITY_SINGLE_TOP) == 0) {
        if (!ret.finishing) {
          int index=indexOfTokenLocked(ret);
          if (index >= 0) {
            finishActivityLocked(ret,index,Activity.RESULT_CANCELED,null,"String_Node_Str");
          }
          return null;
        }
      }
      return ret;
    }
  }
  return null;
}