Program: 709
Project: 709
Buggy source:
/** 
 * Returns the top activity in any existing task matching the given Intent.  Returns null if no such task is found.
 */
ActivityRecord findTaskLocked(ActivityRecord target){
  Intent intent=target.intent;
  ActivityInfo info=target.info;
  ComponentName cls=intent.getComponent();
  if (info.targetActivity != null) {
    cls=new ComponentName(info.packageName,info.targetActivity);
  }
  final int userId=UserHandle.getUserId(info.applicationInfo.uid);
  for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
    final TaskRecord task=mTaskHistory.get(taskNdx);
    if (task.userId != userId) {
      continue;
    }
    final ActivityRecord r=task.getTopActivity();
    if (r == null || r.finishing || r.userId != userId || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
      continue;
    }
    if (task.affinity != null) {
      if (task.affinity.equals(info.taskAffinity)) {
        return r;
      }
    }
 else     if (task.intent != null && task.intent.getComponent().equals(cls)) {
      return r;
    }
 else     if (task.affinityIntent != null && task.affinityIntent.getComponent().equals(cls)) {
      return r;
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Returns the top activity in any existing task matching the given Intent.  Returns null if no such task is found.
 */
ActivityRecord findTaskLocked(ActivityRecord target){
  Intent intent=target.intent;
  ActivityInfo info=target.info;
  ComponentName cls=intent.getComponent();
  if (info.targetActivity != null) {
    cls=new ComponentName(info.packageName,info.targetActivity);
  }
  final int userId=UserHandle.getUserId(info.applicationInfo.uid);
  if (DEBUG_TASKS)   Slog.d(TAG,"String_Node_Str" + target + "String_Node_Str"+ this);
  for (int taskNdx=mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
    final TaskRecord task=mTaskHistory.get(taskNdx);
    if (task.userId != userId) {
      if (DEBUG_TASKS)       Slog.d(TAG,"String_Node_Str" + task + "String_Node_Str");
      continue;
    }
    final ActivityRecord r=task.getTopActivity();
    if (r == null || r.finishing || r.userId != userId || r.launchMode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
      if (DEBUG_TASKS)       Slog.d(TAG,"String_Node_Str" + task + "String_Node_Str"+ r);
      continue;
    }
    if (DEBUG_TASKS)     Slog.d(TAG,"String_Node_Str" + r.task.intent.getComponent().flattenToShortString() + "String_Node_Str"+ r.task.affinity+ "String_Node_Str"+ intent.getComponent().flattenToShortString()+ "String_Node_Str"+ info.taskAffinity);
    if (task.affinity != null) {
      if (task.affinity.equals(info.taskAffinity)) {
        if (DEBUG_TASKS)         Slog.d(TAG,"String_Node_Str");
        return r;
      }
    }
 else     if (task.intent != null && task.intent.getComponent().equals(cls)) {
      if (DEBUG_TASKS)       Slog.d(TAG,"String_Node_Str");
      if (DEBUG_TASKS)       Slog.d(TAG,"String_Node_Str" + intent + "String_Node_Str"+ r.intent);
      return r;
    }
 else     if (task.affinityIntent != null && task.affinityIntent.getComponent().equals(cls)) {
      if (DEBUG_TASKS)       Slog.d(TAG,"String_Node_Str");
      if (DEBUG_TASKS)       Slog.d(TAG,"String_Node_Str" + intent + "String_Node_Str"+ r.intent);
      return r;
    }
 else     if (DEBUG_TASKS) {
      Slog.d(TAG,"String_Node_Str" + task);
    }
  }
  return null;
}