Program: 191845
Project: 191845
Buggy source:
/** 
 * Removes the input task from this stack.
 * @param task to remove.
 * @param reason for removal.
 * @param moving task to another stack. In the case we are moving we don't want to performsome operations on the task like removing it from window manager or recents.
 */
void removeTask(TaskRecord task,String reason,boolean moving){
  if (!moving) {
    mStackSupervisor.removeLockedTaskLocked(task);
    mWindowManager.removeTask(task.taskId);
    if (!StackId.persistTaskBounds(mStackId)) {
      task.updateOverrideConfiguration(null);
    }
  }
  final ActivityRecord r=mResumedActivity;
  if (r != null && r.task == task) {
    mResumedActivity=null;
  }
  final int taskNdx=mTaskHistory.indexOf(task);
  final int topTaskNdx=mTaskHistory.size() - 1;
  if (task.isOverHomeStack() && taskNdx < topTaskNdx) {
    final TaskRecord nextTask=mTaskHistory.get(taskNdx + 1);
    if (!nextTask.isOverHomeStack()) {
      nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
    }
  }
  mTaskHistory.remove(task);
  updateTaskMovement(task,true);
  if (!moving && task.mActivities.isEmpty()) {
    final boolean isVoiceSession=task.voiceSession != null;
    if (isVoiceSession) {
      try {
        task.voiceSession.taskFinished(task.intent,task.taskId);
      }
 catch (      RemoteException e) {
      }
    }
    if (task.autoRemoveFromRecents() || isVoiceSession) {
      mRecentTasks.remove(task);
      task.removedFromRecents();
    }
  }
  if (mTaskHistory.isEmpty()) {
    if (DEBUG_STACK)     Slog.i(TAG_STACK,"String_Node_Str" + this);
    if (isOnHomeDisplay() && mStackSupervisor.isFocusedStack(this)) {
      String myReason=reason + "String_Node_Str";
      if (mFullscreen || !adjustFocusToNextFocusableStackLocked(task.getTaskToReturnTo(),myReason)) {
        mStackSupervisor.moveHomeStackToFront(myReason);
      }
    }
    if (mStacks != null) {
      mStacks.remove(this);
      mStacks.add(0,this);
    }
    if (!isHomeStack()) {
      mActivityContainer.onTaskListEmptyLocked();
    }
  }
  task.stack=null;
}

Fixed version (ground truth):
/** 
 * Removes the input task from this stack.
 * @param task to remove.
 * @param reason for removal.
 * @param mode task removal mode. Either {@link #REMOVE_TASK_MODE_DESTROYING},  {@link #REMOVE_TASK_MODE_MOVING},   {@link #REMOVE_TASK_MODE_MOVING_TO_TOP}.
 */
void removeTask(TaskRecord task,String reason,int mode){
  if (mode == REMOVE_TASK_MODE_DESTROYING) {
    mStackSupervisor.removeLockedTaskLocked(task);
    mWindowManager.removeTask(task.taskId);
    if (!StackId.persistTaskBounds(mStackId)) {
      task.updateOverrideConfiguration(null);
    }
  }
  final ActivityRecord r=mResumedActivity;
  if (r != null && r.task == task) {
    mResumedActivity=null;
  }
  final int taskNdx=mTaskHistory.indexOf(task);
  final int topTaskNdx=mTaskHistory.size() - 1;
  if (task.isOverHomeStack() && taskNdx < topTaskNdx) {
    final TaskRecord nextTask=mTaskHistory.get(taskNdx + 1);
    if (!nextTask.isOverHomeStack()) {
      nextTask.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
    }
  }
  mTaskHistory.remove(task);
  updateTaskMovement(task,true);
  if (mode == REMOVE_TASK_MODE_DESTROYING && task.mActivities.isEmpty()) {
    final boolean isVoiceSession=task.voiceSession != null;
    if (isVoiceSession) {
      try {
        task.voiceSession.taskFinished(task.intent,task.taskId);
      }
 catch (      RemoteException e) {
      }
    }
    if (task.autoRemoveFromRecents() || isVoiceSession) {
      mRecentTasks.remove(task);
      task.removedFromRecents();
    }
  }
  if (mTaskHistory.isEmpty()) {
    if (DEBUG_STACK)     Slog.i(TAG_STACK,"String_Node_Str" + this);
    if (isOnHomeDisplay() && mode != REMOVE_TASK_MODE_MOVING_TO_TOP && mStackSupervisor.isFocusedStack(this)) {
      String myReason=reason + "String_Node_Str";
      if (mFullscreen || !adjustFocusToNextFocusableStackLocked(task.getTaskToReturnTo(),myReason)) {
        mStackSupervisor.moveHomeStackToFront(myReason);
      }
    }
    if (mStacks != null) {
      mStacks.remove(this);
      mStacks.add(0,this);
    }
    if (!isHomeStack()) {
      mActivityContainer.onTaskListEmptyLocked();
    }
  }
  task.stack=null;
}