Program: 199473
Project: 199473
Buggy source:
/** 
 * Reload the set of recent tasks 
 */
SpaceNode reload(Context context,int preloadCount){
  Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str");
  Resources res=context.getResources();
  ArrayList<Task> tasksToForceLoad=new ArrayList<Task>();
  TaskStack stack=new TaskStack(context);
  SpaceNode root=new SpaceNode(context);
  root.setStack(stack);
  try {
    long t1=System.currentTimeMillis();
    PackageManager pm=context.getPackageManager();
    ActivityManager am=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RecentTaskInfo> tasks=am.getRecentTasksForUser(25,ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_RELATED,UserHandle.CURRENT.getIdentifier());
    Collections.reverse(tasks);
    Console.log(Constants.DebugFlags.App.TimeSystemCalls,"String_Node_Str","String_Node_Str" + (System.currentTimeMillis() - t1) + "String_Node_Str");
    Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str","String_Node_Str" + tasks.size());
    Iterator<ActivityManager.RecentTaskInfo> iter=tasks.iterator();
    while (iter.hasNext()) {
      ActivityManager.RecentTaskInfo t=iter.next();
      if (am.isInHomeStack(t.persistentId)) {
        iter.remove();
        continue;
      }
      if (t.baseIntent.getComponent().getPackageName().equals(context.getPackageName())) {
        iter.remove();
        continue;
      }
    }
    t1=System.currentTimeMillis();
    int taskCount=tasks.size();
    for (int i=0; i < taskCount; i++) {
      ActivityManager.RecentTaskInfo t=tasks.get(i);
      ActivityInfo info=pm.getActivityInfo(t.baseIntent.getComponent(),PackageManager.GET_META_DATA);
      String title=info.loadLabel(pm).toString();
      boolean isForemostTask=(i == (taskCount - 1));
      if (i >= (taskCount - preloadCount)) {
        Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str","String_Node_Str" + i + "String_Node_Str"+ t.baseIntent.getComponent().getPackageName());
        String label=(t.activityLabel == null ? title : t.activityLabel.toString());
        BitmapDrawable bd=null;
        if (t.activityIcon != null) {
          bd=new BitmapDrawable(res,t.activityIcon);
        }
        Task task=new Task(t.persistentId,t.baseIntent,label,bd);
        if (task.icon != null) {
          mIconCache.put(task.key,task.icon);
        }
 else {
          if (!isForemostTask) {
            task.icon=mIconCache.get(task.key);
            if (task.icon != null) {
              tasksToForceLoad.add(task);
            }
          }
          if (task.icon == null) {
            task.icon=info.loadIcon(pm);
            if (task.icon != null) {
              mIconCache.put(task.key,task.icon);
            }
 else {
              task.icon=mDefaultIcon;
            }
          }
        }
        if (!isForemostTask) {
          task.thumbnail=mThumbnailCache.get(task.key);
          if (task.thumbnail != null) {
            tasksToForceLoad.add(task);
          }
        }
        if (task.thumbnail == null) {
          Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str");
          task.thumbnail=am.getTaskTopThumbnail(t.id);
          if (task.thumbnail != null) {
            mThumbnailCache.put(task.key,task.thumbnail);
          }
 else {
            task.thumbnail=mDefaultThumbnail;
          }
        }
        for (int j=0; j < Constants.Values.RecentsTaskLoader.TaskEntryMultiplier; j++) {
          Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str",t.baseIntent.getComponent().getPackageName());
          stack.addTask(task);
        }
      }
 else {
        for (int j=0; j < Constants.Values.RecentsTaskLoader.TaskEntryMultiplier; j++) {
          Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str",t.baseIntent.getComponent().getPackageName());
          stack.addTask(new Task(t.persistentId,t.baseIntent,title,null,null));
        }
      }
    }
    Console.log(Constants.DebugFlags.App.TimeSystemCalls,"String_Node_Str","String_Node_Str" + (System.currentTimeMillis() - t1) + "String_Node_Str");
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  mLoader.start(context);
  for (  Task t : tasksToForceLoad) {
    mLoadQueue.addTask(t,true);
  }
  return root;
}

Fixed version (ground truth):
/** 
 * Reload the set of recent tasks 
 */
SpaceNode reload(Context context,int preloadCount){
  Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str");
  Resources res=context.getResources();
  ArrayList<Task> tasksToForceLoad=new ArrayList<Task>();
  TaskStack stack=new TaskStack(context);
  SpaceNode root=new SpaceNode(context);
  root.setStack(stack);
  try {
    long t1=System.currentTimeMillis();
    PackageManager pm=context.getPackageManager();
    ActivityManager am=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RecentTaskInfo> tasks=am.getRecentTasksForUser(25,ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_RELATED,UserHandle.CURRENT.getIdentifier());
    Collections.reverse(tasks);
    Console.log(Constants.DebugFlags.App.TimeSystemCalls,"String_Node_Str","String_Node_Str" + (System.currentTimeMillis() - t1) + "String_Node_Str");
    Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str","String_Node_Str" + tasks.size());
    Iterator<ActivityManager.RecentTaskInfo> iter=tasks.iterator();
    while (iter.hasNext()) {
      ActivityManager.RecentTaskInfo t=iter.next();
      if (am.isInHomeStack(t.persistentId)) {
        iter.remove();
        continue;
      }
      if (t.baseIntent.getComponent().getPackageName().equals(context.getPackageName())) {
        iter.remove();
        continue;
      }
    }
    t1=System.currentTimeMillis();
    int taskCount=tasks.size();
    for (int i=0; i < taskCount; i++) {
      ActivityManager.RecentTaskInfo t=tasks.get(i);
      ActivityInfo info=pm.getActivityInfo(t.baseIntent.getComponent(),PackageManager.GET_META_DATA);
      String title=info.loadLabel(pm).toString();
      boolean isForemostTask=(i == (taskCount - 1));
      if (i >= (taskCount - preloadCount)) {
        Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str","String_Node_Str" + i + "String_Node_Str"+ t.baseIntent.getComponent().getPackageName());
        String label=(t.activityLabel == null ? title : t.activityLabel.toString());
        BitmapDrawable bd=null;
        if (t.activityIcon != null) {
          bd=new BitmapDrawable(res,t.activityIcon);
        }
        Task task=new Task(t.persistentId,(t.id > -1),t.baseIntent,label,bd);
        if (task.icon != null) {
          mIconCache.put(task.key,task.icon);
        }
 else {
          if (!isForemostTask) {
            task.icon=mIconCache.get(task.key);
            if (task.icon != null) {
              tasksToForceLoad.add(task);
            }
          }
          if (task.icon == null) {
            task.icon=info.loadIcon(pm);
            if (task.icon != null) {
              mIconCache.put(task.key,task.icon);
            }
 else {
              task.icon=mDefaultIcon;
            }
          }
        }
        if (!isForemostTask) {
          task.thumbnail=mThumbnailCache.get(task.key);
          if (task.thumbnail != null) {
            tasksToForceLoad.add(task);
          }
        }
        if (task.thumbnail == null) {
          Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str");
          task.thumbnail=am.getTaskTopThumbnail(t.id);
          if (task.thumbnail != null) {
            mThumbnailCache.put(task.key,task.thumbnail);
          }
 else {
            task.thumbnail=mDefaultThumbnail;
          }
        }
        for (int j=0; j < Constants.Values.RecentsTaskLoader.TaskEntryMultiplier; j++) {
          Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str",t.baseIntent.getComponent().getPackageName());
          stack.addTask(task);
        }
      }
 else {
        for (int j=0; j < Constants.Values.RecentsTaskLoader.TaskEntryMultiplier; j++) {
          Console.log(Constants.DebugFlags.App.TaskDataLoader,"String_Node_Str",t.baseIntent.getComponent().getPackageName());
          stack.addTask(new Task(t.persistentId,(t.id > -1),t.baseIntent,title,null,null));
        }
      }
    }
    Console.log(Constants.DebugFlags.App.TimeSystemCalls,"String_Node_Str","String_Node_Str" + (System.currentTimeMillis() - t1) + "String_Node_Str");
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  mLoader.start(context);
  for (  Task t : tasksToForceLoad) {
    mLoadQueue.addTask(t,true);
  }
  return root;
}