Program: 2003
Project: 2003
Buggy source:
private int findAppWindowInsertionPointLocked(AppWindowToken target){
  final int taskId=target.groupId;
  Task targetTask=mTaskIdToTask.get(taskId);
  if (targetTask == null) {
    Slog.w(TAG,"String_Node_Str" + target + "String_Node_Str"+ taskId);
    return 0;
  }
  DisplayContent displayContent=targetTask.getDisplayContent();
  if (displayContent == null) {
    Slog.w(TAG,"String_Node_Str" + target);
    return 0;
  }
  final WindowList windows=displayContent.getWindowList();
  final int NW=windows.size();
  boolean found=false;
  final ArrayList<Task> tasks=displayContent.getTasks();
  for (int taskNdx=tasks.size() - 1; taskNdx >= 0; --taskNdx) {
    final Task task=tasks.get(taskNdx);
    if (!found && task.taskId != taskId) {
      continue;
    }
    AppTokenList tokens=task.mAppTokens;
    for (int tokenNdx=tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
      final AppWindowToken wtoken=tokens.get(tokenNdx);
      if (!found && wtoken == target) {
        found=true;
      }
      if (found) {
        if (DEBUG_REORDER)         Slog.v(TAG,"String_Node_Str" + wtoken.token);
        if (wtoken.sendingToBottom) {
          if (DEBUG_REORDER)           Slog.v(TAG,"String_Node_Str");
          continue;
        }
        for (int i=wtoken.windows.size() - 1; i >= 0; --i) {
          WindowState win=wtoken.windows.get(i);
          for (int j=win.mChildWindows.size() - 1; j >= 0; --j) {
            WindowState cwin=win.mChildWindows.get(j);
            if (cwin.mSubLayer >= 0) {
              for (int pos=NW - 1; pos >= 0; pos--) {
                if (windows.get(pos) == cwin) {
                  if (DEBUG_REORDER)                   Slog.v(TAG,"String_Node_Str" + (pos + 1));
                  return pos + 1;
                }
              }
            }
          }
          for (int pos=NW - 1; pos >= 0; pos--) {
            if (windows.get(pos) == win) {
              if (DEBUG_REORDER)               Slog.v(TAG,"String_Node_Str" + (pos + 1));
              return pos + 1;
            }
          }
        }
      }
    }
  }
  return 0;
}

Fixed version (ground truth):
private int findAppWindowInsertionPointLocked(AppWindowToken target){
  final int taskId=target.groupId;
  Task targetTask=mTaskIdToTask.get(taskId);
  if (targetTask == null) {
    Slog.w(TAG,"String_Node_Str" + target + "String_Node_Str"+ taskId);
    return 0;
  }
  DisplayContent displayContent=targetTask.getDisplayContent();
  if (displayContent == null) {
    Slog.w(TAG,"String_Node_Str" + target);
    return 0;
  }
  final WindowList windows=displayContent.getWindowList();
  final int NW=windows.size();
  boolean found=false;
  final ArrayList<Task> tasks=displayContent.getTasks();
  for (int taskNdx=tasks.size() - 1; taskNdx >= 0; --taskNdx) {
    final Task task=tasks.get(taskNdx);
    if (!found && task.taskId != taskId) {
      continue;
    }
    AppTokenList tokens=task.mAppTokens;
    for (int tokenNdx=tokens.size() - 1; tokenNdx >= 0; --tokenNdx) {
      final AppWindowToken wtoken=tokens.get(tokenNdx);
      if (!found && wtoken == target) {
        found=true;
      }
      if (found) {
        if (DEBUG_REORDER)         Slog.v(TAG,"String_Node_Str" + wtoken.token);
        if (wtoken.sendingToBottom) {
          if (DEBUG_REORDER)           Slog.v(TAG,"String_Node_Str");
          continue;
        }
        for (int i=wtoken.windows.size() - 1; i >= 0; --i) {
          WindowState win=wtoken.windows.get(i);
          for (int j=win.mChildWindows.size() - 1; j >= 0; --j) {
            WindowState cwin=win.mChildWindows.get(j);
            if (cwin.mSubLayer >= 0) {
              for (int pos=NW - 1; pos >= 0; pos--) {
                if (windows.get(pos) == cwin) {
                  if (DEBUG_REORDER)                   Slog.v(TAG,"String_Node_Str" + (pos + 1));
                  return pos + 1;
                }
              }
            }
          }
          for (int pos=NW - 1; pos >= 0; pos--) {
            if (windows.get(pos) == win) {
              if (DEBUG_REORDER)               Slog.v(TAG,"String_Node_Str" + (pos + 1));
              return pos + 1;
            }
          }
        }
      }
    }
  }
  for (int pos=NW - 1; pos >= 0; pos--) {
    if (windows.get(pos).mIsWallpaper) {
      if (DEBUG_REORDER)       Slog.v(TAG,"String_Node_Str" + pos);
      return pos + 1;
    }
  }
  return 0;
}