Program: 1174
Project: 1174
Buggy source:
public ArrayList<ProcessState> collectProcessesLocked(int[] screenStates,int[] memStates,int[] procStates,int sortProcStates[],long now,String reqPackage){
  ArraySet<ProcessState> foundProcs=new ArraySet<ProcessState>();
  ArrayMap<String,SparseArray<PackageState>> pkgMap=mPackages.getMap();
  for (int ip=0; ip < pkgMap.size(); ip++) {
    if (reqPackage != null && !reqPackage.equals(pkgMap.keyAt(ip))) {
      continue;
    }
    SparseArray<PackageState> procs=pkgMap.valueAt(ip);
    for (int iu=0; iu < procs.size(); iu++) {
      PackageState state=procs.valueAt(iu);
      for (int iproc=0; iproc < state.mProcesses.size(); iproc++) {
        ProcessState proc=state.mProcesses.valueAt(iproc);
        foundProcs.add(proc.mCommonProcess);
      }
    }
  }
  ArrayList<ProcessState> outProcs=new ArrayList<ProcessState>(foundProcs.size());
  for (int i=0; i < foundProcs.size(); i++) {
    ProcessState proc=foundProcs.valueAt(i);
    if (computeProcessTimeLocked(proc,screenStates,memStates,procStates,now) > 0) {
      outProcs.add(proc);
      if (procStates != sortProcStates) {
        computeProcessTimeLocked(proc,screenStates,memStates,sortProcStates,now);
      }
    }
  }
  Collections.sort(outProcs,new Comparator<ProcessState>(){
    @Override public int compare(    ProcessState lhs,    ProcessState rhs){
      if (lhs.mTmpTotalTime < rhs.mTmpTotalTime) {
        return -1;
      }
 else       if (lhs.mTmpTotalTime > rhs.mTmpTotalTime) {
        return 1;
      }
      return 0;
    }
  }
);
  return outProcs;
}

Fixed version (ground truth):
public ArrayList<ProcessState> collectProcessesLocked(int[] screenStates,int[] memStates,int[] procStates,int sortProcStates[],long now,String reqPackage,boolean activeOnly){
  ArraySet<ProcessState> foundProcs=new ArraySet<ProcessState>();
  ArrayMap<String,SparseArray<PackageState>> pkgMap=mPackages.getMap();
  for (int ip=0; ip < pkgMap.size(); ip++) {
    if (reqPackage != null && !reqPackage.equals(pkgMap.keyAt(ip))) {
      continue;
    }
    SparseArray<PackageState> procs=pkgMap.valueAt(ip);
    for (int iu=0; iu < procs.size(); iu++) {
      PackageState state=procs.valueAt(iu);
      for (int iproc=0; iproc < state.mProcesses.size(); iproc++) {
        ProcessState proc=state.mProcesses.valueAt(iproc);
        if (activeOnly && !proc.isInUse()) {
          continue;
        }
        foundProcs.add(proc.mCommonProcess);
      }
    }
  }
  ArrayList<ProcessState> outProcs=new ArrayList<ProcessState>(foundProcs.size());
  for (int i=0; i < foundProcs.size(); i++) {
    ProcessState proc=foundProcs.valueAt(i);
    if (computeProcessTimeLocked(proc,screenStates,memStates,procStates,now) > 0) {
      outProcs.add(proc);
      if (procStates != sortProcStates) {
        computeProcessTimeLocked(proc,screenStates,memStates,sortProcStates,now);
      }
    }
  }
  Collections.sort(outProcs,new Comparator<ProcessState>(){
    @Override public int compare(    ProcessState lhs,    ProcessState rhs){
      if (lhs.mTmpTotalTime < rhs.mTmpTotalTime) {
        return -1;
      }
 else       if (lhs.mTmpTotalTime > rhs.mTmpTotalTime) {
        return 1;
      }
      return 0;
    }
  }
);
  return outProcs;
}