Program: 80565
Project: 80565
Buggy source:
protected void buildTasks(){
  Runnable runnable=new Runnable(){
    @Override public void run(){
      try {
        boolean isToggled=prefs.getBoolean(Settings.TOGGLE_PREFERENCE,Settings.TOGGLE_DEFAULT);
        boolean smartNotification=prefs.getBoolean(Settings.SMART_NOTIFICATION_PREFERENCE,Settings.SMART_NOTIFICATION_DEFAULT);
        final ActivityManager activityManager=(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        final List<ActivityManager.RunningTaskInfo> recentTasks=activityManager.getRunningTasks(MAX_RUNNING_TASKS);
        final Context mContext=getApplicationContext();
        pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
        if (recentTasks != null && recentTasks.size() > 0) {
          ComponentName task=recentTasks.get(0).baseActivity;
          String taskClass=task.getClassName();
          String taskPackage=task.getPackageName();
          if (launcherPackage != null && taskPackage != null && taskPackage.equals(launcherPackage)) {
            if (runningTask == null || !runningTask.packageName.equals(taskPackage)) {
              Tools.HangarLog("String_Node_Str");
              Tools.updateWidget(mContext);
              runningTask=new TaskInfo(taskPackage);
              buildReorderAndLaunch(isToggled & !isNotificationRunning);
            }
            return;
          }
          if (taskClass.equals("String_Node_Str") || Tools.isBlacklistedOrBad(taskPackage,mContext,db)) {
            buildReorderAndLaunch(isToggled & !isNotificationRunning);
            return;
          }
          if (runningTask != null && runningTask.packageName.equals(taskPackage)) {
            if (pm.isScreenOn()) {
              runningTask.seconds+=LOOP_SECONDS;
              if (runningTask.seconds >= LOOP_SECONDS * 5) {
                db.addSeconds(taskPackage,runningTask.seconds);
                runningTask.totalseconds+=runningTask.seconds;
                runningTask.seconds=0;
              }
            }
            return;
          }
          buildTaskInfo(taskClass,taskPackage);
          if (taskClass.equals(getPackageName())) {
            buildReorderAndLaunch(isToggled & !isNotificationRunning);
            return;
          }
          if (smartNotification) {
            if (notificationTasks != null && new Tools().isInArray(notificationTasks,taskPackage)) {
              buildReorderAndLaunch(isToggled & !isNotificationRunning);
              return;
            }
          }
 else {
            if (new Tools().isPinned(mContext,taskPackage)) {
              buildReorderAndLaunch(isToggled & !isNotificationRunning);
              return;
            }
          }
        }
        buildReorderAndLaunch(isToggled);
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
  }
;
  new Thread(runnable).start();
}

Fixed version (ground truth):
protected void buildTasks(){
  Runnable runnable=new Runnable(){
    @Override public void run(){
      try {
        boolean isToggled=prefs.getBoolean(Settings.TOGGLE_PREFERENCE,Settings.TOGGLE_DEFAULT);
        boolean smartNotification=prefs.getBoolean(Settings.SMART_NOTIFICATION_PREFERENCE,Settings.SMART_NOTIFICATION_DEFAULT);
        final ActivityManager activityManager=(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        final List<ActivityManager.RunningTaskInfo> recentTasks=activityManager.getRunningTasks(MAX_RUNNING_TASKS);
        final Context mContext=getApplicationContext();
        pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
        if (recentTasks != null && recentTasks.size() > 0) {
          ComponentName task=recentTasks.get(0).baseActivity;
          String taskClass=task.getClassName();
          String taskPackage=task.getPackageName();
          if (launcherPackage != null && taskPackage != null && taskPackage.equals(launcherPackage)) {
            if (runningTask == null || !runningTask.packageName.equals(taskPackage)) {
              if (!isToggled && isAppsWidget()) {
                taskList=Tools.buildTaskList(getApplicationContext(),db,Settings.TASKLIST_QUEUE_LIMIT);
                reorderAndLaunch(taskList,true);
              }
              Tools.HangarLog("String_Node_Str");
              Tools.updateWidget(mContext);
              runningTask=new TaskInfo(taskPackage);
              buildReorderAndLaunch(isToggled & !isNotificationRunning);
            }
            return;
          }
          if (taskClass.equals("String_Node_Str") || Tools.isBlacklistedOrBad(taskPackage,mContext,db)) {
            buildReorderAndLaunch(isToggled & !isNotificationRunning);
            return;
          }
          if (runningTask != null && runningTask.packageName.equals(taskPackage)) {
            if (pm.isScreenOn()) {
              runningTask.seconds+=LOOP_SECONDS;
              if (runningTask.seconds >= LOOP_SECONDS * 5) {
                db.addSeconds(taskPackage,runningTask.seconds);
                runningTask.totalseconds+=runningTask.seconds;
                runningTask.seconds=0;
              }
            }
            return;
          }
          buildTaskInfo(taskClass,taskPackage);
          if (taskClass.equals(getPackageName())) {
            buildReorderAndLaunch(isToggled & !isNotificationRunning);
            return;
          }
          if (smartNotification && isToggled) {
            if (notificationTasks != null && new Tools().isInArray(notificationTasks,taskPackage)) {
              buildReorderAndLaunch(!isNotificationRunning);
              return;
            }
          }
          if (new Tools().isPinned(mContext,taskPackage)) {
            buildReorderAndLaunch(isToggled & !isNotificationRunning);
            return;
          }
        }
        buildReorderAndLaunch(isToggled);
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
  }
;
  new Thread(runnable).start();
}