nus-yam/ex-repair huggingface dataset:
Program: 196084
Project: 196084
Buggy source:
public void handleSwipe(View view){
  TaskDescription ad=((ViewHolder)view.getTag()).taskDescription;
  if (ad == null) {
    Log.v(TAG,"String_Node_Str" + view + "String_Node_Str"+ view.getTag());
    return;
  }
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + ad.getLabel());
  mRecentTaskDescriptions.remove(ad);
  mRecentTasksLoader.remove(ad);
  if (mRecentTaskDescriptions.size() == 0) {
    dismissAndGoBack();
  }
  final ActivityManager am=(ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
  if (am != null) {
    am.removeTask(ad.persistentTaskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
    setContentDescription(getContext().getString(R.string.accessibility_recents_item_dismissed,ad.getLabel()));
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
    setContentDescription(null);
  }
}

Fixed version (ground truth):
public void handleSwipe(View view){
  TaskDescription ad=((ViewHolder)view.getTag()).taskDescription;
  if (ad == null) {
    Log.v(TAG,"String_Node_Str" + view + "String_Node_Str"+ view.getTag());
    return;
  }
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + ad.getLabel());
  mRecentTaskDescriptions.remove(ad);
  mRecentTasksLoader.remove(ad);
  if (mRecentTaskDescriptions.size() == 0) {
    dismissAndGoBack();
  }
  final ActivityManager am=(ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
  if (am != null) {
    am.removeTask(ad.persistentTaskId);
    setContentDescription(getContext().getString(R.string.accessibility_recents_item_dismissed,ad.getLabel()));
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
    setContentDescription(null);
  }
}
Program: 196085
Project: 196085
Buggy source:
/** 
 * Removes the task and kills the process 
 */
public void removeTask(int taskId,boolean isDocument){
  if (mAm == null)   return;
  if (Constants.DebugFlags.App.EnableSystemServicesProxy)   return;
  mAm.removeTask(taskId,isDocument ? 0 : ActivityManager.REMOVE_TASK_KILL_PROCESS);
}

Fixed version (ground truth):
/** 
 * Removes the task 
 */
public void removeTask(int taskId){
  if (mAm == null)   return;
  if (Constants.DebugFlags.App.EnableSystemServicesProxy)   return;
  mAm.removeTask(taskId);
}
Program: 196086
Project: 196086
Buggy source:
@Override public void onTaskViewDismissed(Task t){
  RecentsTaskLoader loader=RecentsTaskLoader.getInstance();
  loader.deleteTaskData(t,false);
  RecentsTaskLoader.getInstance().getSystemServicesProxy().removeTask(t.key.id,Utilities.isDocument(t.key.baseIntent));
}

Fixed version (ground truth):
@Override public void onTaskViewDismissed(Task t){
  RecentsTaskLoader loader=RecentsTaskLoader.getInstance();
  loader.deleteTaskData(t,false);
  RecentsTaskLoader.getInstance().getSystemServicesProxy().removeTask(t.key.id);
}
Program: 196087
Project: 196087
Buggy source:
@Override public void onPackageRemoved(String packageName,int uid){
  final int eventUserId=getChangingUserId();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      ComponentName cn=tr.intent.getComponent();
      if (cn != null && cn.getPackageName().equals(packageName)) {
        removeTaskByIdLocked(tr.taskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void onPackageRemoved(String packageName,int uid){
  final int eventUserId=getChangingUserId();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      ComponentName cn=tr.intent.getComponent();
      if (cn != null && cn.getPackageName().equals(packageName)) {
        removeTaskByIdLocked(tr.taskId,true);
      }
    }
  }
}
Program: 196090
Project: 196090
Buggy source:
@Override public boolean removeTask(int taskId,int flags){
synchronized (this) {
    enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,"String_Node_Str");
    long ident=Binder.clearCallingIdentity();
    try {
      return removeTaskByIdLocked(taskId,flags);
    }
  finally {
      Binder.restoreCallingIdentity(ident);
    }
  }
}

Fixed version (ground truth):
@Override public boolean removeTask(int taskId){
synchronized (this) {
    enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,"String_Node_Str");
    long ident=Binder.clearCallingIdentity();
    try {
      return removeTaskByIdLocked(taskId,true);
    }
  finally {
      Binder.restoreCallingIdentity(ident);
    }
  }
}
Program: 196091
Project: 196091
Buggy source:
@Override public void finishAndRemoveTask(){
  checkCaller();
synchronized (ActivityManagerService.this) {
    long origId=Binder.clearCallingIdentity();
    try {
      TaskRecord tr=recentTaskForIdLocked(mTaskId);
      if (tr == null) {
        throw new IllegalArgumentException("String_Node_Str" + mTaskId);
      }
      int flags=tr.getBaseIntent().getFlags();
      boolean isDocument=(flags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) == Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
      removeTaskByIdLocked(mTaskId,!isDocument ? ActivityManager.REMOVE_TASK_KILL_PROCESS : 0);
    }
  finally {
      Binder.restoreCallingIdentity(origId);
    }
  }
}

Fixed version (ground truth):
@Override public void finishAndRemoveTask(){
  checkCaller();
synchronized (ActivityManagerService.this) {
    long origId=Binder.clearCallingIdentity();
    try {
      if (!removeTaskByIdLocked(mTaskId,false)) {
        throw new IllegalArgumentException("String_Node_Str" + mTaskId);
      }
    }
  finally {
      Binder.restoreCallingIdentity(origId);
    }
  }
}
Program: 196092
Project: 196092
Buggy source:
/** 
 * Removes the task with the specified task id.
 * @param taskId Identifier of the task to be removed.
 * @param flags Additional operational flags.  May be 0 or{@link ActivityManager#REMOVE_TASK_KILL_PROCESS}.
 * @return Returns true if the given task was found and removed.
 */
private boolean removeTaskByIdLocked(int taskId,int flags){
  TaskRecord tr=recentTaskForIdLocked(taskId);
  if (tr != null) {
    tr.removeTaskActivitiesLocked();
    cleanUpRemovedTaskLocked(tr,flags);
    if (tr.isPersistable) {
      notifyTaskPersisterLocked(null,true);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Removes the task with the specified task id.
 * @param taskId Identifier of the task to be removed.
 * @param killProcess Kill any process associated with the task if possible.
 * @return Returns true if the given task was found and removed.
 */
private boolean removeTaskByIdLocked(int taskId,boolean killProcess){
  TaskRecord tr=recentTaskForIdLocked(taskId);
  if (tr != null) {
    tr.removeTaskActivitiesLocked();
    cleanUpRemovedTaskLocked(tr,killProcess);
    if (tr.isPersistable) {
      notifyTaskPersisterLocked(null,true);
    }
    return true;
  }
  return false;
}
Program: 196093
Project: 196093
Buggy source:
@Override public void onPackageModified(String packageName){
  final int eventUserId=getChangingUserId();
  final IPackageManager pm=AppGlobals.getPackageManager();
  final ArrayList<Pair<Intent,Integer>> recentTaskIntents=new ArrayList<Pair<Intent,Integer>>();
  final HashSet<ComponentName> componentsKnownToExist=new HashSet<ComponentName>();
  final ArrayList<Integer> tasksToRemove=new ArrayList<Integer>();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      recentTaskIntents.add(new Pair<Intent,Integer>(tr.intent,tr.taskId));
    }
  }
  for (int i=recentTaskIntents.size() - 1; i >= 0; i--) {
    Pair<Intent,Integer> p=recentTaskIntents.get(i);
    ComponentName cn=p.first.getComponent();
    if (cn != null && cn.getPackageName().equals(packageName)) {
      if (componentsKnownToExist.contains(cn)) {
        continue;
      }
      try {
        ActivityInfo info=pm.getActivityInfo(cn,0,eventUserId);
        if (info != null) {
          componentsKnownToExist.add(cn);
        }
 else {
          tasksToRemove.add(p.second);
        }
      }
 catch (      RemoteException e) {
        Log.e(TAG,"String_Node_Str" + cn,e);
      }
    }
  }
synchronized (ActivityManagerService.this) {
    for (int i=tasksToRemove.size() - 1; i >= 0; i--) {
      removeTaskByIdLocked(tasksToRemove.get(i),0);
    }
  }
}

Fixed version (ground truth):
@Override public void onPackageModified(String packageName){
  final int eventUserId=getChangingUserId();
  final IPackageManager pm=AppGlobals.getPackageManager();
  final ArrayList<Pair<Intent,Integer>> recentTaskIntents=new ArrayList<Pair<Intent,Integer>>();
  final HashSet<ComponentName> componentsKnownToExist=new HashSet<ComponentName>();
  final ArrayList<Integer> tasksToRemove=new ArrayList<Integer>();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      recentTaskIntents.add(new Pair<Intent,Integer>(tr.intent,tr.taskId));
    }
  }
  for (int i=recentTaskIntents.size() - 1; i >= 0; i--) {
    Pair<Intent,Integer> p=recentTaskIntents.get(i);
    ComponentName cn=p.first.getComponent();
    if (cn != null && cn.getPackageName().equals(packageName)) {
      if (componentsKnownToExist.contains(cn)) {
        continue;
      }
      try {
        ActivityInfo info=pm.getActivityInfo(cn,0,eventUserId);
        if (info != null) {
          componentsKnownToExist.add(cn);
        }
 else {
          tasksToRemove.add(p.second);
        }
      }
 catch (      RemoteException e) {
        Log.e(TAG,"String_Node_Str" + cn,e);
      }
    }
  }
synchronized (ActivityManagerService.this) {
    for (int i=tasksToRemove.size() - 1; i >= 0; i--) {
      removeTaskByIdLocked(tasksToRemove.get(i),false);
    }
  }
}
Program: 196094
Project: 196094
Buggy source:
private void cleanUpRemovedTaskLocked(TaskRecord tr,int flags){
  mRecentTasks.remove(tr);
  tr.removedFromRecents(mTaskPersister);
  final boolean killProcesses=(flags & ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
  Intent baseIntent=new Intent(tr.intent != null ? tr.intent : tr.affinityIntent);
  ComponentName component=baseIntent.getComponent();
  if (component == null) {
    Slog.w(TAG,"String_Node_Str" + tr);
    return;
  }
  mServices.cleanUpRemovedTaskLocked(tr,component,baseIntent);
  if (killProcesses) {
    final String pkg=component.getPackageName();
    ArrayList<ProcessRecord> procs=new ArrayList<ProcessRecord>();
    ArrayMap<String,SparseArray<ProcessRecord>> pmap=mProcessNames.getMap();
    for (int i=0; i < pmap.size(); i++) {
      SparseArray<ProcessRecord> uids=pmap.valueAt(i);
      for (int j=0; j < uids.size(); j++) {
        ProcessRecord proc=uids.valueAt(j);
        if (proc.userId != tr.userId) {
          continue;
        }
        if (!proc.pkgList.containsKey(pkg)) {
          continue;
        }
        procs.add(proc);
      }
    }
    for (int i=0; i < procs.size(); i++) {
      ProcessRecord pr=procs.get(i);
      if (pr == mHomeProcess) {
        continue;
      }
      if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
        pr.kill("String_Node_Str",true);
      }
 else {
        pr.waitingToKill="String_Node_Str";
      }
    }
  }
}

Fixed version (ground truth):
private void cleanUpRemovedTaskLocked(TaskRecord tr,boolean killProcess){
  mRecentTasks.remove(tr);
  tr.removedFromRecents(mTaskPersister);
  ComponentName component=tr.getBaseIntent().getComponent();
  if (component == null) {
    Slog.w(TAG,"String_Node_Str" + tr);
    return;
  }
  if (!killProcess) {
    return;
  }
  final String pkg=component.getPackageName();
  ArrayList<ProcessRecord> procsToKill=new ArrayList<ProcessRecord>();
  ArrayMap<String,SparseArray<ProcessRecord>> pmap=mProcessNames.getMap();
  for (int i=0; i < pmap.size(); i++) {
    SparseArray<ProcessRecord> uids=pmap.valueAt(i);
    for (int j=0; j < uids.size(); j++) {
      ProcessRecord proc=uids.valueAt(j);
      if (proc.userId != tr.userId) {
        continue;
      }
      if (proc == mHomeProcess) {
        continue;
      }
      if (!proc.pkgList.containsKey(pkg)) {
        continue;
      }
      for (int k=0; k < proc.activities.size(); k++) {
        TaskRecord otherTask=proc.activities.get(k).task;
        if (tr.taskId != otherTask.taskId && otherTask.inRecents) {
          return;
        }
      }
      procsToKill.add(proc);
    }
  }
  mServices.cleanUpRemovedTaskLocked(tr,component,new Intent(tr.getBaseIntent()));
  for (int i=0; i < procsToKill.size(); i++) {
    ProcessRecord pr=procsToKill.get(i);
    if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
      pr.kill("String_Node_Str",true);
    }
 else {
      pr.waitingToKill="String_Node_Str";
    }
  }
}
Program: 196095
Project: 196095
Buggy source:
@Override public boolean onLongClick(View v){
  if (task.id >= 0 && thumbs != null) {
    mAm.removeTask(task.id,ActivityManager.REMOVE_TASK_KILL_PROCESS);
    buildUi();
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean onLongClick(View v){
  if (task.id >= 0 && thumbs != null) {
    mAm.removeTask(task.id);
    buildUi();
    return true;
  }
  return false;
}
Program: 196096
Project: 196096
Buggy source:
private void addThumbnail(LinearLayout container,Bitmap bm,final ActivityManager.RecentTaskInfo task,final ActivityManager.TaskThumbnail thumbs){
  ImageView iv=new ImageView(this);
  if (bm != null) {
    iv.setImageBitmap(bm);
  }
  iv.setBackgroundResource(android.R.drawable.gallery_thumb);
  int w=getResources().getDimensionPixelSize(android.R.dimen.thumbnail_width);
  int h=getResources().getDimensionPixelSize(android.R.dimen.thumbnail_height);
  container.addView(iv,new LinearLayout.LayoutParams(w,h));
  iv.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      if (task.id >= 0 && thumbs != null) {
        mAm.moveTaskToFront(task.id,ActivityManager.MOVE_TASK_WITH_HOME);
      }
 else {
        try {
          startActivity(task.baseIntent);
        }
 catch (        ActivityNotFoundException e) {
          Log.w("String_Node_Str","String_Node_Str" + e);
        }
      }
      buildUi();
    }
  }
);
  iv.setOnLongClickListener(new View.OnLongClickListener(){
    @Override public boolean onLongClick(    View v){
      if (task.id >= 0 && thumbs != null) {
        mAm.removeTask(task.id,ActivityManager.REMOVE_TASK_KILL_PROCESS);
        buildUi();
        return true;
      }
      return false;
    }
  }
);
}

Fixed version (ground truth):
private void addThumbnail(LinearLayout container,Bitmap bm,final ActivityManager.RecentTaskInfo task,final ActivityManager.TaskThumbnail thumbs){
  ImageView iv=new ImageView(this);
  if (bm != null) {
    iv.setImageBitmap(bm);
  }
  iv.setBackgroundResource(android.R.drawable.gallery_thumb);
  int w=getResources().getDimensionPixelSize(android.R.dimen.thumbnail_width);
  int h=getResources().getDimensionPixelSize(android.R.dimen.thumbnail_height);
  container.addView(iv,new LinearLayout.LayoutParams(w,h));
  iv.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      if (task.id >= 0 && thumbs != null) {
        mAm.moveTaskToFront(task.id,ActivityManager.MOVE_TASK_WITH_HOME);
      }
 else {
        try {
          startActivity(task.baseIntent);
        }
 catch (        ActivityNotFoundException e) {
          Log.w("String_Node_Str","String_Node_Str" + e);
        }
      }
      buildUi();
    }
  }
);
  iv.setOnLongClickListener(new View.OnLongClickListener(){
    @Override public boolean onLongClick(    View v){
      if (task.id >= 0 && thumbs != null) {
        mAm.removeTask(task.id);
        buildUi();
        return true;
      }
      return false;
    }
  }
);
}
Program: 196097
Project: 196097
Buggy source:
/** 
 * Completely remove the given task.
 * @param taskId Identifier of the task to be removed.
 * @param flags Additional operational flags.  May be 0 or{@link #REMOVE_TASK_KILL_PROCESS}.
 * @return Returns true if the given task was found and removed.
 * @hide
 */
public boolean removeTask(int taskId,int flags) throws SecurityException {
  try {
    return ActivityManagerNative.getDefault().removeTask(taskId,flags);
  }
 catch (  RemoteException e) {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Completely remove the given task.
 * @param taskId Identifier of the task to be removed.
 * @return Returns true if the given task was found and removed.
 * @hide
 */
public boolean removeTask(int taskId) throws SecurityException {
  try {
    return ActivityManagerNative.getDefault().removeTask(taskId);
  }
 catch (  RemoteException e) {
    return false;
  }
}
Program: 196099
Project: 196099
Buggy source:
public boolean removeTask(int taskId,int flags) throws RemoteException {
  Parcel data=Parcel.obtain();
  Parcel reply=Parcel.obtain();
  data.writeInterfaceToken(IActivityManager.descriptor);
  data.writeInt(taskId);
  data.writeInt(flags);
  mRemote.transact(REMOVE_TASK_TRANSACTION,data,reply,0);
  reply.readException();
  boolean result=reply.readInt() != 0;
  reply.recycle();
  data.recycle();
  return result;
}

Fixed version (ground truth):
public boolean removeTask(int taskId) throws RemoteException {
  Parcel data=Parcel.obtain();
  Parcel reply=Parcel.obtain();
  data.writeInterfaceToken(IActivityManager.descriptor);
  data.writeInt(taskId);
  mRemote.transact(REMOVE_TASK_TRANSACTION,data,reply,0);
  reply.readException();
  boolean result=reply.readInt() != 0;
  reply.recycle();
  data.recycle();
  return result;
}
Program: 196100
Project: 196100
Buggy source:
public boolean removeTask(int taskId,int flags) throws RemoteException ;

Fixed version (ground truth):
public boolean removeTask(int taskId) throws RemoteException ;
Program: 196101
Project: 196101
Buggy source:
public void handleSwipe(View view){
  TaskDescription ad=((ViewHolder)view.getTag()).taskDescription;
  if (ad == null) {
    Log.v(TAG,"String_Node_Str" + view + "String_Node_Str"+ view.getTag());
    return;
  }
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + ad.getLabel());
  mRecentTaskDescriptions.remove(ad);
  mRecentTasksLoader.remove(ad);
  if (mRecentTaskDescriptions.size() == 0) {
    dismissAndGoBack();
  }
  final ActivityManager am=(ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
  if (am != null) {
    am.removeTask(ad.persistentTaskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
    setContentDescription(getContext().getString(R.string.accessibility_recents_item_dismissed,ad.getLabel()));
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
    setContentDescription(null);
  }
}

Fixed version (ground truth):
public void handleSwipe(View view){
  TaskDescription ad=((ViewHolder)view.getTag()).taskDescription;
  if (ad == null) {
    Log.v(TAG,"String_Node_Str" + view + "String_Node_Str"+ view.getTag());
    return;
  }
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + ad.getLabel());
  mRecentTaskDescriptions.remove(ad);
  mRecentTasksLoader.remove(ad);
  if (mRecentTaskDescriptions.size() == 0) {
    dismissAndGoBack();
  }
  final ActivityManager am=(ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
  if (am != null) {
    am.removeTask(ad.persistentTaskId);
    setContentDescription(getContext().getString(R.string.accessibility_recents_item_dismissed,ad.getLabel()));
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
    setContentDescription(null);
  }
}
Program: 196102
Project: 196102
Buggy source:
/** 
 * Removes the task and kills the process 
 */
public void removeTask(int taskId,boolean isDocument){
  if (mAm == null)   return;
  if (Constants.DebugFlags.App.EnableSystemServicesProxy)   return;
  mAm.removeTask(taskId,isDocument ? 0 : ActivityManager.REMOVE_TASK_KILL_PROCESS);
}

Fixed version (ground truth):
/** 
 * Removes the task 
 */
public void removeTask(int taskId){
  if (mAm == null)   return;
  if (Constants.DebugFlags.App.EnableSystemServicesProxy)   return;
  mAm.removeTask(taskId);
}
Program: 196103
Project: 196103
Buggy source:
@Override public void onTaskViewDismissed(Task t){
  RecentsTaskLoader loader=RecentsTaskLoader.getInstance();
  loader.deleteTaskData(t,false);
  RecentsTaskLoader.getInstance().getSystemServicesProxy().removeTask(t.key.id,Utilities.isDocument(t.key.baseIntent));
}

Fixed version (ground truth):
@Override public void onTaskViewDismissed(Task t){
  RecentsTaskLoader loader=RecentsTaskLoader.getInstance();
  loader.deleteTaskData(t,false);
  RecentsTaskLoader.getInstance().getSystemServicesProxy().removeTask(t.key.id);
}
Program: 196104
Project: 196104
Buggy source:
@Override public void onPackageRemoved(String packageName,int uid){
  final int eventUserId=getChangingUserId();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      ComponentName cn=tr.intent.getComponent();
      if (cn != null && cn.getPackageName().equals(packageName)) {
        removeTaskByIdLocked(tr.taskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void onPackageRemoved(String packageName,int uid){
  final int eventUserId=getChangingUserId();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      ComponentName cn=tr.intent.getComponent();
      if (cn != null && cn.getPackageName().equals(packageName)) {
        removeTaskByIdLocked(tr.taskId,true);
      }
    }
  }
}
Program: 196107
Project: 196107
Buggy source:
@Override public boolean removeTask(int taskId,int flags){
synchronized (this) {
    enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,"String_Node_Str");
    long ident=Binder.clearCallingIdentity();
    try {
      return removeTaskByIdLocked(taskId,flags);
    }
  finally {
      Binder.restoreCallingIdentity(ident);
    }
  }
}

Fixed version (ground truth):
@Override public boolean removeTask(int taskId){
synchronized (this) {
    enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,"String_Node_Str");
    long ident=Binder.clearCallingIdentity();
    try {
      return removeTaskByIdLocked(taskId,true);
    }
  finally {
      Binder.restoreCallingIdentity(ident);
    }
  }
}
Program: 196108
Project: 196108
Buggy source:
@Override public void finishAndRemoveTask(){
  checkCaller();
synchronized (ActivityManagerService.this) {
    long origId=Binder.clearCallingIdentity();
    try {
      TaskRecord tr=recentTaskForIdLocked(mTaskId);
      if (tr == null) {
        throw new IllegalArgumentException("String_Node_Str" + mTaskId);
      }
      int flags=tr.getBaseIntent().getFlags();
      boolean isDocument=(flags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) == Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
      removeTaskByIdLocked(mTaskId,!isDocument ? ActivityManager.REMOVE_TASK_KILL_PROCESS : 0);
    }
  finally {
      Binder.restoreCallingIdentity(origId);
    }
  }
}

Fixed version (ground truth):
@Override public void finishAndRemoveTask(){
  checkCaller();
synchronized (ActivityManagerService.this) {
    long origId=Binder.clearCallingIdentity();
    try {
      if (!removeTaskByIdLocked(mTaskId,false)) {
        throw new IllegalArgumentException("String_Node_Str" + mTaskId);
      }
    }
  finally {
      Binder.restoreCallingIdentity(origId);
    }
  }
}
Program: 196109
Project: 196109
Buggy source:
/** 
 * Removes the task with the specified task id.
 * @param taskId Identifier of the task to be removed.
 * @param flags Additional operational flags.  May be 0 or{@link ActivityManager#REMOVE_TASK_KILL_PROCESS}.
 * @return Returns true if the given task was found and removed.
 */
private boolean removeTaskByIdLocked(int taskId,int flags){
  TaskRecord tr=recentTaskForIdLocked(taskId);
  if (tr != null) {
    tr.removeTaskActivitiesLocked();
    cleanUpRemovedTaskLocked(tr,flags);
    if (tr.isPersistable) {
      notifyTaskPersisterLocked(null,true);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Removes the task with the specified task id.
 * @param taskId Identifier of the task to be removed.
 * @param killProcess Kill any process associated with the task if possible.
 * @return Returns true if the given task was found and removed.
 */
private boolean removeTaskByIdLocked(int taskId,boolean killProcess){
  TaskRecord tr=recentTaskForIdLocked(taskId);
  if (tr != null) {
    tr.removeTaskActivitiesLocked();
    cleanUpRemovedTaskLocked(tr,killProcess);
    if (tr.isPersistable) {
      notifyTaskPersisterLocked(null,true);
    }
    return true;
  }
  return false;
}
Program: 196110
Project: 196110
Buggy source:
@Override public void onPackageModified(String packageName){
  final int eventUserId=getChangingUserId();
  final IPackageManager pm=AppGlobals.getPackageManager();
  final ArrayList<Pair<Intent,Integer>> recentTaskIntents=new ArrayList<Pair<Intent,Integer>>();
  final HashSet<ComponentName> componentsKnownToExist=new HashSet<ComponentName>();
  final ArrayList<Integer> tasksToRemove=new ArrayList<Integer>();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      recentTaskIntents.add(new Pair<Intent,Integer>(tr.intent,tr.taskId));
    }
  }
  for (int i=recentTaskIntents.size() - 1; i >= 0; i--) {
    Pair<Intent,Integer> p=recentTaskIntents.get(i);
    ComponentName cn=p.first.getComponent();
    if (cn != null && cn.getPackageName().equals(packageName)) {
      if (componentsKnownToExist.contains(cn)) {
        continue;
      }
      try {
        ActivityInfo info=pm.getActivityInfo(cn,0,eventUserId);
        if (info != null) {
          componentsKnownToExist.add(cn);
        }
 else {
          tasksToRemove.add(p.second);
        }
      }
 catch (      RemoteException e) {
        Log.e(TAG,"String_Node_Str" + cn,e);
      }
    }
  }
synchronized (ActivityManagerService.this) {
    for (int i=tasksToRemove.size() - 1; i >= 0; i--) {
      removeTaskByIdLocked(tasksToRemove.get(i),0);
    }
  }
}

Fixed version (ground truth):
@Override public void onPackageModified(String packageName){
  final int eventUserId=getChangingUserId();
  final IPackageManager pm=AppGlobals.getPackageManager();
  final ArrayList<Pair<Intent,Integer>> recentTaskIntents=new ArrayList<Pair<Intent,Integer>>();
  final HashSet<ComponentName> componentsKnownToExist=new HashSet<ComponentName>();
  final ArrayList<Integer> tasksToRemove=new ArrayList<Integer>();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      recentTaskIntents.add(new Pair<Intent,Integer>(tr.intent,tr.taskId));
    }
  }
  for (int i=recentTaskIntents.size() - 1; i >= 0; i--) {
    Pair<Intent,Integer> p=recentTaskIntents.get(i);
    ComponentName cn=p.first.getComponent();
    if (cn != null && cn.getPackageName().equals(packageName)) {
      if (componentsKnownToExist.contains(cn)) {
        continue;
      }
      try {
        ActivityInfo info=pm.getActivityInfo(cn,0,eventUserId);
        if (info != null) {
          componentsKnownToExist.add(cn);
        }
 else {
          tasksToRemove.add(p.second);
        }
      }
 catch (      RemoteException e) {
        Log.e(TAG,"String_Node_Str" + cn,e);
      }
    }
  }
synchronized (ActivityManagerService.this) {
    for (int i=tasksToRemove.size() - 1; i >= 0; i--) {
      removeTaskByIdLocked(tasksToRemove.get(i),false);
    }
  }
}
Program: 196111
Project: 196111
Buggy source:
private void cleanUpRemovedTaskLocked(TaskRecord tr,int flags){
  mRecentTasks.remove(tr);
  tr.removedFromRecents(mTaskPersister);
  final boolean killProcesses=(flags & ActivityManager.REMOVE_TASK_KILL_PROCESS) != 0;
  Intent baseIntent=new Intent(tr.intent != null ? tr.intent : tr.affinityIntent);
  ComponentName component=baseIntent.getComponent();
  if (component == null) {
    Slog.w(TAG,"String_Node_Str" + tr);
    return;
  }
  mServices.cleanUpRemovedTaskLocked(tr,component,baseIntent);
  if (killProcesses) {
    final String pkg=component.getPackageName();
    ArrayList<ProcessRecord> procs=new ArrayList<ProcessRecord>();
    ArrayMap<String,SparseArray<ProcessRecord>> pmap=mProcessNames.getMap();
    for (int i=0; i < pmap.size(); i++) {
      SparseArray<ProcessRecord> uids=pmap.valueAt(i);
      for (int j=0; j < uids.size(); j++) {
        ProcessRecord proc=uids.valueAt(j);
        if (proc.userId != tr.userId) {
          continue;
        }
        if (!proc.pkgList.containsKey(pkg)) {
          continue;
        }
        procs.add(proc);
      }
    }
    for (int i=0; i < procs.size(); i++) {
      ProcessRecord pr=procs.get(i);
      if (pr == mHomeProcess) {
        continue;
      }
      if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
        pr.kill("String_Node_Str",true);
      }
 else {
        pr.waitingToKill="String_Node_Str";
      }
    }
  }
}

Fixed version (ground truth):
private void cleanUpRemovedTaskLocked(TaskRecord tr,boolean killProcess){
  mRecentTasks.remove(tr);
  tr.removedFromRecents(mTaskPersister);
  ComponentName component=tr.getBaseIntent().getComponent();
  if (component == null) {
    Slog.w(TAG,"String_Node_Str" + tr);
    return;
  }
  if (!killProcess) {
    return;
  }
  final String pkg=component.getPackageName();
  ArrayList<ProcessRecord> procsToKill=new ArrayList<ProcessRecord>();
  ArrayMap<String,SparseArray<ProcessRecord>> pmap=mProcessNames.getMap();
  for (int i=0; i < pmap.size(); i++) {
    SparseArray<ProcessRecord> uids=pmap.valueAt(i);
    for (int j=0; j < uids.size(); j++) {
      ProcessRecord proc=uids.valueAt(j);
      if (proc.userId != tr.userId) {
        continue;
      }
      if (proc == mHomeProcess) {
        continue;
      }
      if (!proc.pkgList.containsKey(pkg)) {
        continue;
      }
      for (int k=0; k < proc.activities.size(); k++) {
        TaskRecord otherTask=proc.activities.get(k).task;
        if (tr.taskId != otherTask.taskId && otherTask.inRecents) {
          return;
        }
      }
      procsToKill.add(proc);
    }
  }
  mServices.cleanUpRemovedTaskLocked(tr,component,new Intent(tr.getBaseIntent()));
  for (int i=0; i < procsToKill.size(); i++) {
    ProcessRecord pr=procsToKill.get(i);
    if (pr.setSchedGroup == Process.THREAD_GROUP_BG_NONINTERACTIVE) {
      pr.kill("String_Node_Str",true);
    }
 else {
      pr.waitingToKill="String_Node_Str";
    }
  }
}
Program: 196112
Project: 196112
Buggy source:
@Override public boolean onLongClick(View v){
  if (task.id >= 0 && thumbs != null) {
    mAm.removeTask(task.id,ActivityManager.REMOVE_TASK_KILL_PROCESS);
    buildUi();
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean onLongClick(View v){
  if (task.id >= 0 && thumbs != null) {
    mAm.removeTask(task.id);
    buildUi();
    return true;
  }
  return false;
}
Program: 196113
Project: 196113
Buggy source:
private void addThumbnail(LinearLayout container,Bitmap bm,final ActivityManager.RecentTaskInfo task,final ActivityManager.TaskThumbnail thumbs){
  ImageView iv=new ImageView(this);
  if (bm != null) {
    iv.setImageBitmap(bm);
  }
  iv.setBackgroundResource(android.R.drawable.gallery_thumb);
  int w=getResources().getDimensionPixelSize(android.R.dimen.thumbnail_width);
  int h=getResources().getDimensionPixelSize(android.R.dimen.thumbnail_height);
  container.addView(iv,new LinearLayout.LayoutParams(w,h));
  iv.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      if (task.id >= 0 && thumbs != null) {
        mAm.moveTaskToFront(task.id,ActivityManager.MOVE_TASK_WITH_HOME);
      }
 else {
        try {
          startActivity(task.baseIntent);
        }
 catch (        ActivityNotFoundException e) {
          Log.w("String_Node_Str","String_Node_Str" + e);
        }
      }
      buildUi();
    }
  }
);
  iv.setOnLongClickListener(new View.OnLongClickListener(){
    @Override public boolean onLongClick(    View v){
      if (task.id >= 0 && thumbs != null) {
        mAm.removeTask(task.id,ActivityManager.REMOVE_TASK_KILL_PROCESS);
        buildUi();
        return true;
      }
      return false;
    }
  }
);
}

Fixed version (ground truth):
private void addThumbnail(LinearLayout container,Bitmap bm,final ActivityManager.RecentTaskInfo task,final ActivityManager.TaskThumbnail thumbs){
  ImageView iv=new ImageView(this);
  if (bm != null) {
    iv.setImageBitmap(bm);
  }
  iv.setBackgroundResource(android.R.drawable.gallery_thumb);
  int w=getResources().getDimensionPixelSize(android.R.dimen.thumbnail_width);
  int h=getResources().getDimensionPixelSize(android.R.dimen.thumbnail_height);
  container.addView(iv,new LinearLayout.LayoutParams(w,h));
  iv.setOnClickListener(new View.OnClickListener(){
    @Override public void onClick(    View v){
      if (task.id >= 0 && thumbs != null) {
        mAm.moveTaskToFront(task.id,ActivityManager.MOVE_TASK_WITH_HOME);
      }
 else {
        try {
          startActivity(task.baseIntent);
        }
 catch (        ActivityNotFoundException e) {
          Log.w("String_Node_Str","String_Node_Str" + e);
        }
      }
      buildUi();
    }
  }
);
  iv.setOnLongClickListener(new View.OnLongClickListener(){
    @Override public boolean onLongClick(    View v){
      if (task.id >= 0 && thumbs != null) {
        mAm.removeTask(task.id);
        buildUi();
        return true;
      }
      return false;
    }
  }
);
}
Program: 196114
Project: 196114
Buggy source:
/** 
 * Completely remove the given task.
 * @param taskId Identifier of the task to be removed.
 * @param flags Additional operational flags.  May be 0 or{@link #REMOVE_TASK_KILL_PROCESS}.
 * @return Returns true if the given task was found and removed.
 * @hide
 */
public boolean removeTask(int taskId,int flags) throws SecurityException {
  try {
    return ActivityManagerNative.getDefault().removeTask(taskId,flags);
  }
 catch (  RemoteException e) {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Completely remove the given task.
 * @param taskId Identifier of the task to be removed.
 * @return Returns true if the given task was found and removed.
 * @hide
 */
public boolean removeTask(int taskId) throws SecurityException {
  try {
    return ActivityManagerNative.getDefault().removeTask(taskId);
  }
 catch (  RemoteException e) {
    return false;
  }
}
Program: 196116
Project: 196116
Buggy source:
public boolean removeTask(int taskId,int flags) throws RemoteException {
  Parcel data=Parcel.obtain();
  Parcel reply=Parcel.obtain();
  data.writeInterfaceToken(IActivityManager.descriptor);
  data.writeInt(taskId);
  data.writeInt(flags);
  mRemote.transact(REMOVE_TASK_TRANSACTION,data,reply,0);
  reply.readException();
  boolean result=reply.readInt() != 0;
  reply.recycle();
  data.recycle();
  return result;
}

Fixed version (ground truth):
public boolean removeTask(int taskId) throws RemoteException {
  Parcel data=Parcel.obtain();
  Parcel reply=Parcel.obtain();
  data.writeInterfaceToken(IActivityManager.descriptor);
  data.writeInt(taskId);
  mRemote.transact(REMOVE_TASK_TRANSACTION,data,reply,0);
  reply.readException();
  boolean result=reply.readInt() != 0;
  reply.recycle();
  data.recycle();
  return result;
}
Program: 196117
Project: 196117
Buggy source:
public boolean removeTask(int taskId,int flags) throws RemoteException ;

Fixed version (ground truth):
public boolean removeTask(int taskId) throws RemoteException ;
Program: 196118
Project: 196118
Buggy source:
public void handleSwipe(View view){
  TaskDescription ad=((ViewHolder)view.getTag()).taskDescription;
  if (ad == null) {
    Log.v(TAG,"String_Node_Str" + view + "String_Node_Str"+ view.getTag());
    return;
  }
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + ad.getLabel());
  mRecentTaskDescriptions.remove(ad);
  mRecentTasksLoader.remove(ad);
  if (mRecentTaskDescriptions.size() == 0) {
    dismissAndGoBack();
  }
  final ActivityManager am=(ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
  if (am != null) {
    am.removeTask(ad.persistentTaskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
    setContentDescription(getContext().getString(R.string.accessibility_recents_item_dismissed,ad.getLabel()));
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
    setContentDescription(null);
  }
}

Fixed version (ground truth):
public void handleSwipe(View view){
  TaskDescription ad=((ViewHolder)view.getTag()).taskDescription;
  if (ad == null) {
    Log.v(TAG,"String_Node_Str" + view + "String_Node_Str"+ view.getTag());
    return;
  }
  if (DEBUG)   Log.v(TAG,"String_Node_Str" + ad.getLabel());
  mRecentTaskDescriptions.remove(ad);
  mRecentTasksLoader.remove(ad);
  if (mRecentTaskDescriptions.size() == 0) {
    dismissAndGoBack();
  }
  final ActivityManager am=(ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
  if (am != null) {
    am.removeTask(ad.persistentTaskId);
    setContentDescription(getContext().getString(R.string.accessibility_recents_item_dismissed,ad.getLabel()));
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
    setContentDescription(null);
  }
}
Program: 196119
Project: 196119
Buggy source:
/** 
 * Removes the task and kills the process 
 */
public void removeTask(int taskId,boolean isDocument){
  if (mAm == null)   return;
  if (Constants.DebugFlags.App.EnableSystemServicesProxy)   return;
  mAm.removeTask(taskId,isDocument ? 0 : ActivityManager.REMOVE_TASK_KILL_PROCESS);
}

Fixed version (ground truth):
/** 
 * Removes the task 
 */
public void removeTask(int taskId){
  if (mAm == null)   return;
  if (Constants.DebugFlags.App.EnableSystemServicesProxy)   return;
  mAm.removeTask(taskId);
}
Program: 196120
Project: 196120
Buggy source:
@Override public void onTaskViewDismissed(Task t){
  RecentsTaskLoader loader=RecentsTaskLoader.getInstance();
  loader.deleteTaskData(t,false);
  RecentsTaskLoader.getInstance().getSystemServicesProxy().removeTask(t.key.id,Utilities.isDocument(t.key.baseIntent));
}

Fixed version (ground truth):
@Override public void onTaskViewDismissed(Task t){
  RecentsTaskLoader loader=RecentsTaskLoader.getInstance();
  loader.deleteTaskData(t,false);
  RecentsTaskLoader.getInstance().getSystemServicesProxy().removeTask(t.key.id);
}
Program: 196121
Project: 196121
Buggy source:
@Override public void onPackageRemoved(String packageName,int uid){
  final int eventUserId=getChangingUserId();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      ComponentName cn=tr.intent.getComponent();
      if (cn != null && cn.getPackageName().equals(packageName)) {
        removeTaskByIdLocked(tr.taskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void onPackageRemoved(String packageName,int uid){
  final int eventUserId=getChangingUserId();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      ComponentName cn=tr.intent.getComponent();
      if (cn != null && cn.getPackageName().equals(packageName)) {
        removeTaskByIdLocked(tr.taskId,true);
      }
    }
  }
}
Program: 196124
Project: 196124
Buggy source:
@Override public boolean removeTask(int taskId,int flags){
synchronized (this) {
    enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,"String_Node_Str");
    long ident=Binder.clearCallingIdentity();
    try {
      return removeTaskByIdLocked(taskId,flags);
    }
  finally {
      Binder.restoreCallingIdentity(ident);
    }
  }
}

Fixed version (ground truth):
@Override public boolean removeTask(int taskId){
synchronized (this) {
    enforceCallingPermission(android.Manifest.permission.REMOVE_TASKS,"String_Node_Str");
    long ident=Binder.clearCallingIdentity();
    try {
      return removeTaskByIdLocked(taskId,true);
    }
  finally {
      Binder.restoreCallingIdentity(ident);
    }
  }
}
Program: 196125
Project: 196125
Buggy source:
@Override public void finishAndRemoveTask(){
  checkCaller();
synchronized (ActivityManagerService.this) {
    long origId=Binder.clearCallingIdentity();
    try {
      TaskRecord tr=recentTaskForIdLocked(mTaskId);
      if (tr == null) {
        throw new IllegalArgumentException("String_Node_Str" + mTaskId);
      }
      int flags=tr.getBaseIntent().getFlags();
      boolean isDocument=(flags & Intent.FLAG_ACTIVITY_NEW_DOCUMENT) == Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
      removeTaskByIdLocked(mTaskId,!isDocument ? ActivityManager.REMOVE_TASK_KILL_PROCESS : 0);
    }
  finally {
      Binder.restoreCallingIdentity(origId);
    }
  }
}

Fixed version (ground truth):
@Override public void finishAndRemoveTask(){
  checkCaller();
synchronized (ActivityManagerService.this) {
    long origId=Binder.clearCallingIdentity();
    try {
      if (!removeTaskByIdLocked(mTaskId,false)) {
        throw new IllegalArgumentException("String_Node_Str" + mTaskId);
      }
    }
  finally {
      Binder.restoreCallingIdentity(origId);
    }
  }
}
Program: 196126
Project: 196126
Buggy source:
/** 
 * Removes the task with the specified task id.
 * @param taskId Identifier of the task to be removed.
 * @param flags Additional operational flags.  May be 0 or{@link ActivityManager#REMOVE_TASK_KILL_PROCESS}.
 * @return Returns true if the given task was found and removed.
 */
private boolean removeTaskByIdLocked(int taskId,int flags){
  TaskRecord tr=recentTaskForIdLocked(taskId);
  if (tr != null) {
    tr.removeTaskActivitiesLocked();
    cleanUpRemovedTaskLocked(tr,flags);
    if (tr.isPersistable) {
      notifyTaskPersisterLocked(null,true);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Removes the task with the specified task id.
 * @param taskId Identifier of the task to be removed.
 * @param killProcess Kill any process associated with the task if possible.
 * @return Returns true if the given task was found and removed.
 */
private boolean removeTaskByIdLocked(int taskId,boolean killProcess){
  TaskRecord tr=recentTaskForIdLocked(taskId);
  if (tr != null) {
    tr.removeTaskActivitiesLocked();
    cleanUpRemovedTaskLocked(tr,killProcess);
    if (tr.isPersistable) {
      notifyTaskPersisterLocked(null,true);
    }
    return true;
  }
  return false;
}
Program: 196127
Project: 196127
Buggy source:
@Override public void onPackageModified(String packageName){
  final int eventUserId=getChangingUserId();
  final IPackageManager pm=AppGlobals.getPackageManager();
  final ArrayList<Pair<Intent,Integer>> recentTaskIntents=new ArrayList<Pair<Intent,Integer>>();
  final HashSet<ComponentName> componentsKnownToExist=new HashSet<ComponentName>();
  final ArrayList<Integer> tasksToRemove=new ArrayList<Integer>();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      recentTaskIntents.add(new Pair<Intent,Integer>(tr.intent,tr.taskId));
    }
  }
  for (int i=recentTaskIntents.size() - 1; i >= 0; i--) {
    Pair<Intent,Integer> p=recentTaskIntents.get(i);
    ComponentName cn=p.first.getComponent();
    if (cn != null && cn.getPackageName().equals(packageName)) {
      if (componentsKnownToExist.contains(cn)) {
        continue;
      }
      try {
        ActivityInfo info=pm.getActivityInfo(cn,0,eventUserId);
        if (info != null) {
          componentsKnownToExist.add(cn);
        }
 else {
          tasksToRemove.add(p.second);
        }
      }
 catch (      RemoteException e) {
        Log.e(TAG,"String_Node_Str" + cn,e);
      }
    }
  }
synchronized (ActivityManagerService.this) {
    for (int i=tasksToRemove.size() - 1; i >= 0; i--) {
      removeTaskByIdLocked(tasksToRemove.get(i),0);
    }
  }
}

Fixed version (ground truth):
@Override public void onPackageModified(String packageName){
  final int eventUserId=getChangingUserId();
  final IPackageManager pm=AppGlobals.getPackageManager();
  final ArrayList<Pair<Intent,Integer>> recentTaskIntents=new ArrayList<Pair<Intent,Integer>>();
  final HashSet<ComponentName> componentsKnownToExist=new HashSet<ComponentName>();
  final ArrayList<Integer> tasksToRemove=new ArrayList<Integer>();
synchronized (ActivityManagerService.this) {
    for (int i=mRecentTasks.size() - 1; i >= 0; i--) {
      TaskRecord tr=mRecentTasks.get(i);
      if (tr.userId != eventUserId)       continue;
      recentTaskIntents.add(new Pair<Intent,Integer>(tr.intent,tr.taskId));
    }
  }
  for (int i=recentTaskIntents.size() - 1; i >= 0; i--) {
    Pair<Intent,Integer> p=recentTaskIntents.get(i);
    ComponentName cn=p.first.getComponent();
    if (cn != null && cn.getPackageName().equals(packageName)) {
      if (componentsKnownToExist.contains(cn)) {
        continue;
      }
      try {
        ActivityInfo info=pm.getActivityInfo(cn,0,eventUserId);
        if (info != null) {
          componentsKnownToExist.add(cn);
        }
 else {
          tasksToRemove.add(p.second);
        }
      }
 catch (      RemoteException e) {
        Log.e(TAG,"String_Node_Str" + cn,e);
      }
    }
  }
synchronized (ActivityManagerService.this) {
    for (int i=tasksToRemove.size() - 1; i >= 0; i--) {
      removeTaskByIdLocked(tasksToRemove.get(i),false);
    }
  }
}