Program: 197086
Project: 197086
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);
  boolean isDocument=intent != null & intent.isDocument();
  Uri documentData=isDocument ? intent.getData() : null;
  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.voiceSession != null) {
      if (DEBUG_TASKS)       Slog.d(TAG,"String_Node_Str" + task + "String_Node_Str");
      continue;
    }
    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;
    }
    final Intent taskIntent=task.intent;
    final Intent affinityIntent=task.affinityIntent;
    final boolean taskIsDocument;
    final Uri taskDocumentData;
    if (taskIntent != null && taskIntent.isDocument()) {
      taskIsDocument=true;
      taskDocumentData=taskIntent.getData();
    }
 else     if (affinityIntent != null && affinityIntent.isDocument()) {
      taskIsDocument=true;
      taskDocumentData=affinityIntent.getData();
    }
 else {
      taskIsDocument=false;
      taskDocumentData=null;
    }
    if (DEBUG_TASKS)     Slog.d(TAG,"String_Node_Str" + taskIntent.getComponent().flattenToShortString() + "String_Node_Str"+ r.task.affinity+ "String_Node_Str"+ intent.getComponent().flattenToShortString()+ "String_Node_Str"+ info.taskAffinity);
    if (!isDocument && !taskIsDocument && task.affinity != null) {
      if (task.affinity.equals(target.taskAffinity)) {
        if (DEBUG_TASKS)         Slog.d(TAG,"String_Node_Str");
        return r;
      }
    }
 else     if (taskIntent != null && taskIntent.getComponent() != null && taskIntent.getComponent().compareTo(cls) == 0 && Objects.equals(documentData,taskDocumentData)) {
      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 (affinityIntent != null && affinityIntent.getComponent() != null && affinityIntent.getComponent().compareTo(cls) == 0 && Objects.equals(documentData,taskDocumentData)) {
      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;
}

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);
  boolean isDocument=intent != null & intent.isDocument();
  Uri documentData=isDocument ? intent.getData() : null;
  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.voiceSession != null) {
      if (DEBUG_TASKS)       Slog.d(TAG,"String_Node_Str" + task + "String_Node_Str");
      continue;
    }
    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;
    }
    final Intent taskIntent=task.intent;
    final Intent affinityIntent=task.affinityIntent;
    final boolean taskIsDocument;
    final Uri taskDocumentData;
    if (taskIntent != null && taskIntent.isDocument()) {
      taskIsDocument=true;
      taskDocumentData=taskIntent.getData();
    }
 else     if (affinityIntent != null && affinityIntent.isDocument()) {
      taskIsDocument=true;
      taskDocumentData=affinityIntent.getData();
    }
 else {
      taskIsDocument=false;
      taskDocumentData=null;
    }
    if (DEBUG_TASKS)     Slog.d(TAG,"String_Node_Str" + taskIntent.getComponent().flattenToShortString() + "String_Node_Str"+ r.task.rootAffinity+ "String_Node_Str"+ intent.getComponent().flattenToShortString()+ "String_Node_Str"+ info.taskAffinity);
    if (!isDocument && !taskIsDocument && task.rootAffinity != null) {
      if (task.rootAffinity.equals(target.taskAffinity)) {
        if (DEBUG_TASKS)         Slog.d(TAG,"String_Node_Str");
        return r;
      }
    }
 else     if (taskIntent != null && taskIntent.getComponent() != null && taskIntent.getComponent().compareTo(cls) == 0 && Objects.equals(documentData,taskDocumentData)) {
      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 (affinityIntent != null && affinityIntent.getComponent() != null && affinityIntent.getComponent().compareTo(cls) == 0 && Objects.equals(documentData,taskDocumentData)) {
      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;
}