Program: 2964
Project: 2964
Buggy source:
private final boolean forceStopPackageLocked(String name,int appId,boolean callerWillRestart,boolean purgeCache,boolean doit,boolean evenPersistent,int userId){
  int i;
  int N;
  if (userId == UserHandle.USER_ALL && name == null) {
    Slog.w(TAG,"String_Node_Str");
  }
  if (appId < 0 && name != null) {
    try {
      appId=UserHandle.getAppId(AppGlobals.getPackageManager().getPackageUid(name,0));
    }
 catch (    RemoteException e) {
    }
  }
  if (doit) {
    if (name != null) {
      Slog.i(TAG,"String_Node_Str" + name + "String_Node_Str"+ appId+ "String_Node_Str"+ userId);
    }
 else {
      Slog.i(TAG,"String_Node_Str" + userId);
    }
    Iterator<SparseArray<Long>> badApps=mProcessCrashTimes.getMap().values().iterator();
    while (badApps.hasNext()) {
      SparseArray<Long> ba=badApps.next();
      for (i=ba.size() - 1; i >= 0; i--) {
        boolean remove=false;
        final int entUid=ba.keyAt(i);
        if (name != null) {
          if (userId == UserHandle.USER_ALL) {
            if (UserHandle.getAppId(entUid) == appId) {
              remove=true;
            }
          }
 else {
            if (entUid == UserHandle.getUid(userId,appId)) {
              remove=true;
            }
          }
        }
 else         if (UserHandle.getUserId(entUid) == userId) {
          remove=true;
        }
        if (remove) {
          ba.removeAt(i);
        }
      }
      if (ba.size() == 0) {
        badApps.remove();
      }
    }
  }
  boolean didSomething=killPackageProcessesLocked(name,appId,userId,-100,callerWillRestart,false,doit,evenPersistent,name == null ? ("String_Node_Str" + userId) : ("String_Node_Str" + name));
  TaskRecord lastTask=null;
  for (i=0; i < mMainStack.mHistory.size(); i++) {
    ActivityRecord r=(ActivityRecord)mMainStack.mHistory.get(i);
    final boolean samePackage=r.packageName.equals(name) || (name == null && r.userId == userId);
    if ((userId == UserHandle.USER_ALL || r.userId == userId) && (samePackage || r.task == lastTask) && (r.app == null || evenPersistent || !r.app.persistent)) {
      if (!doit) {
        if (r.finishing) {
          continue;
        }
        return true;
      }
      didSomething=true;
      Slog.i(TAG,"String_Node_Str" + r);
      if (samePackage) {
        if (r.app != null) {
          r.app.removed=true;
        }
        r.app=null;
      }
      lastTask=r.task;
      if (r.stack.finishActivityLocked(r,i,Activity.RESULT_CANCELED,null,"String_Node_Str",true)) {
        i--;
      }
    }
  }
  if (mServices.forceStopLocked(name,userId,evenPersistent,doit)) {
    if (!doit) {
      return true;
    }
    didSomething=true;
  }
  if (name == null) {
    mStickyBroadcasts.remove(userId);
  }
  ArrayList<ContentProviderRecord> providers=new ArrayList<ContentProviderRecord>();
  if (mProviderMap.collectForceStopProviders(name,appId,doit,evenPersistent,userId,providers)) {
    if (!doit) {
      return true;
    }
    didSomething=true;
  }
  N=providers.size();
  for (i=0; i < N; i++) {
    removeDyingProviderLocked(null,providers.get(i),true);
  }
  if (name == null) {
    if (mIntentSenderRecords.size() > 0) {
      Iterator<WeakReference<PendingIntentRecord>> it=mIntentSenderRecords.values().iterator();
      while (it.hasNext()) {
        WeakReference<PendingIntentRecord> wpir=it.next();
        if (wpir == null) {
          it.remove();
          continue;
        }
        PendingIntentRecord pir=wpir.get();
        if (pir == null) {
          it.remove();
          continue;
        }
        if (name == null) {
          if (pir.key.userId != userId) {
            continue;
          }
        }
 else {
          if (UserHandle.getAppId(pir.uid) != appId) {
            continue;
          }
          if (userId != UserHandle.USER_ALL && pir.key.userId != userId) {
            continue;
          }
          if (!pir.key.packageName.equals(name)) {
            continue;
          }
        }
        if (!doit) {
          return true;
        }
        didSomething=true;
        it.remove();
        pir.canceled=true;
        if (pir.key.activity != null) {
          pir.key.activity.pendingResults.remove(pir.ref);
        }
      }
    }
  }
  if (doit) {
    if (purgeCache && name != null) {
      AttributeCache ac=AttributeCache.instance();
      if (ac != null) {
        ac.removePackage(name);
      }
    }
    if (mBooted) {
      mMainStack.resumeTopActivityLocked(null);
      mMainStack.scheduleIdleLocked();
    }
  }
  return didSomething;
}

Fixed version (ground truth):
private final boolean forceStopPackageLocked(String name,int appId,boolean callerWillRestart,boolean purgeCache,boolean doit,boolean evenPersistent,int userId){
  int i;
  int N;
  if (userId == UserHandle.USER_ALL && name == null) {
    Slog.w(TAG,"String_Node_Str");
  }
  if (appId < 0 && name != null) {
    try {
      appId=UserHandle.getAppId(AppGlobals.getPackageManager().getPackageUid(name,0));
    }
 catch (    RemoteException e) {
    }
  }
  if (doit) {
    if (name != null) {
      Slog.i(TAG,"String_Node_Str" + name + "String_Node_Str"+ appId+ "String_Node_Str"+ userId);
    }
 else {
      Slog.i(TAG,"String_Node_Str" + userId);
    }
    Iterator<SparseArray<Long>> badApps=mProcessCrashTimes.getMap().values().iterator();
    while (badApps.hasNext()) {
      SparseArray<Long> ba=badApps.next();
      for (i=ba.size() - 1; i >= 0; i--) {
        boolean remove=false;
        final int entUid=ba.keyAt(i);
        if (name != null) {
          if (userId == UserHandle.USER_ALL) {
            if (UserHandle.getAppId(entUid) == appId) {
              remove=true;
            }
          }
 else {
            if (entUid == UserHandle.getUid(userId,appId)) {
              remove=true;
            }
          }
        }
 else         if (UserHandle.getUserId(entUid) == userId) {
          remove=true;
        }
        if (remove) {
          ba.removeAt(i);
        }
      }
      if (ba.size() == 0) {
        badApps.remove();
      }
    }
  }
  boolean didSomething=killPackageProcessesLocked(name,appId,userId,-100,callerWillRestart,true,doit,evenPersistent,name == null ? ("String_Node_Str" + userId) : ("String_Node_Str" + name));
  TaskRecord lastTask=null;
  for (i=0; i < mMainStack.mHistory.size(); i++) {
    ActivityRecord r=(ActivityRecord)mMainStack.mHistory.get(i);
    final boolean samePackage=r.packageName.equals(name) || (name == null && r.userId == userId);
    if ((userId == UserHandle.USER_ALL || r.userId == userId) && (samePackage || r.task == lastTask) && (r.app == null || evenPersistent || !r.app.persistent)) {
      if (!doit) {
        if (r.finishing) {
          continue;
        }
        return true;
      }
      didSomething=true;
      Slog.i(TAG,"String_Node_Str" + r);
      if (samePackage) {
        if (r.app != null) {
          r.app.removed=true;
        }
        r.app=null;
      }
      lastTask=r.task;
      if (r.stack.finishActivityLocked(r,i,Activity.RESULT_CANCELED,null,"String_Node_Str",true)) {
        i--;
      }
    }
  }
  if (mServices.forceStopLocked(name,userId,evenPersistent,doit)) {
    if (!doit) {
      return true;
    }
    didSomething=true;
  }
  if (name == null) {
    mStickyBroadcasts.remove(userId);
  }
  ArrayList<ContentProviderRecord> providers=new ArrayList<ContentProviderRecord>();
  if (mProviderMap.collectForceStopProviders(name,appId,doit,evenPersistent,userId,providers)) {
    if (!doit) {
      return true;
    }
    didSomething=true;
  }
  N=providers.size();
  for (i=0; i < N; i++) {
    removeDyingProviderLocked(null,providers.get(i),true);
  }
  if (name == null) {
    if (mIntentSenderRecords.size() > 0) {
      Iterator<WeakReference<PendingIntentRecord>> it=mIntentSenderRecords.values().iterator();
      while (it.hasNext()) {
        WeakReference<PendingIntentRecord> wpir=it.next();
        if (wpir == null) {
          it.remove();
          continue;
        }
        PendingIntentRecord pir=wpir.get();
        if (pir == null) {
          it.remove();
          continue;
        }
        if (name == null) {
          if (pir.key.userId != userId) {
            continue;
          }
        }
 else {
          if (UserHandle.getAppId(pir.uid) != appId) {
            continue;
          }
          if (userId != UserHandle.USER_ALL && pir.key.userId != userId) {
            continue;
          }
          if (!pir.key.packageName.equals(name)) {
            continue;
          }
        }
        if (!doit) {
          return true;
        }
        didSomething=true;
        it.remove();
        pir.canceled=true;
        if (pir.key.activity != null) {
          pir.key.activity.pendingResults.remove(pir.ref);
        }
      }
    }
  }
  if (doit) {
    if (purgeCache && name != null) {
      AttributeCache ac=AttributeCache.instance();
      if (ac != null) {
        ac.removePackage(name);
      }
    }
    if (mBooted) {
      mMainStack.resumeTopActivityLocked(null);
      mMainStack.scheduleIdleLocked();
    }
  }
  return didSomething;
}