Program: 302
Project: 302
Buggy source:
public void dumpLocked(PrintWriter pw,String reqPackage,long now,boolean dumpSummary,boolean dumpAll,boolean activeOnly){
  long totalTime=dumpSingleTime(null,null,mMemFactorDurations,mMemFactor,mStartTime,now);
  ArrayMap<String,SparseArray<PackageState>> pkgMap=mPackages.getMap();
  boolean printedHeader=false;
  for (int ip=0; ip < pkgMap.size(); ip++) {
    String pkgName=pkgMap.keyAt(ip);
    if (reqPackage != null && !reqPackage.equals(pkgName)) {
      continue;
    }
    SparseArray<PackageState> uids=pkgMap.valueAt(ip);
    for (int iu=0; iu < uids.size(); iu++) {
      int uid=uids.keyAt(iu);
      PackageState pkgState=uids.valueAt(iu);
      final int NPROCS=pkgState.mProcesses.size();
      final int NSRVS=pkgState.mServices.size();
      if (NPROCS > 0 || NSRVS > 0) {
        if (!printedHeader) {
          pw.println("String_Node_Str");
          printedHeader=true;
        }
        pw.print("String_Node_Str");
        pw.print(pkgName);
        pw.print("String_Node_Str");
        UserHandle.formatUid(pw,uid);
        pw.println("String_Node_Str");
      }
      if (!dumpSummary || dumpAll) {
        for (int iproc=0; iproc < NPROCS; iproc++) {
          ProcessState proc=pkgState.mProcesses.valueAt(iproc);
          if (activeOnly && !proc.isInUse()) {
            pw.print("String_Node_Str");
            pw.print(pkgState.mProcesses.keyAt(iproc));
            pw.println("String_Node_Str");
            continue;
          }
          pw.print("String_Node_Str");
          pw.print(pkgState.mProcesses.keyAt(iproc));
          pw.print("String_Node_Str");
          pw.print(proc.mDurationsTableSize);
          pw.print("String_Node_Str");
          pw.println("String_Node_Str");
          dumpProcessState(pw,"String_Node_Str",proc,ALL_SCREEN_ADJ,ALL_MEM_ADJ,ALL_PROC_STATES,now);
          dumpProcessPss(pw,"String_Node_Str",proc,ALL_SCREEN_ADJ,ALL_MEM_ADJ,ALL_PROC_STATES);
          dumpProcessInternalLocked(pw,"String_Node_Str",proc,dumpAll);
        }
      }
 else {
        ArrayList<ProcessState> procs=new ArrayList<ProcessState>();
        for (int iproc=0; iproc < NPROCS; iproc++) {
          ProcessState proc=pkgState.mProcesses.valueAt(iproc);
          if (activeOnly && !proc.isInUse()) {
            continue;
          }
          procs.add(proc);
        }
        dumpProcessSummaryLocked(pw,"String_Node_Str",procs,ALL_SCREEN_ADJ,ALL_MEM_ADJ,NON_CACHED_PROC_STATES,now,totalTime);
      }
      for (int isvc=0; isvc < NSRVS; isvc++) {
        ServiceState svc=pkgState.mServices.valueAt(isvc);
        if (activeOnly && !svc.isInUse()) {
          pw.print("String_Node_Str");
          pw.print(pkgState.mServices.keyAt(isvc));
          pw.println("String_Node_Str");
          continue;
        }
        if (dumpAll) {
          pw.print("String_Node_Str");
        }
 else {
          pw.print("String_Node_Str");
        }
        pw.print(pkgState.mServices.keyAt(isvc));
        pw.println("String_Node_Str");
        pw.print("String_Node_Str");
        pw.println(svc.mProcessName);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc,svc.mRunCount,ServiceState.SERVICE_RUN,svc.mRunState,svc.mRunStartTime,now,totalTime,!dumpSummary || dumpAll);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc,svc.mStartedCount,ServiceState.SERVICE_STARTED,svc.mStartedState,svc.mStartedStartTime,now,totalTime,!dumpSummary || dumpAll);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc,svc.mBoundCount,ServiceState.SERVICE_BOUND,svc.mBoundState,svc.mBoundStartTime,now,totalTime,!dumpSummary || dumpAll);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc,svc.mExecCount,ServiceState.SERVICE_EXEC,svc.mExecState,svc.mExecStartTime,now,totalTime,!dumpSummary || dumpAll);
        if (dumpAll) {
          if (svc.mOwner != null) {
            pw.print("String_Node_Str");
            pw.println(svc.mOwner);
          }
        }
      }
    }
  }
  if (reqPackage == null) {
    ArrayMap<String,SparseArray<ProcessState>> procMap=mProcesses.getMap();
    printedHeader=false;
    int numShownProcs=0, numTotalProcs=0;
    for (int ip=0; ip < procMap.size(); ip++) {
      String procName=procMap.keyAt(ip);
      SparseArray<ProcessState> uids=procMap.valueAt(ip);
      for (int iu=0; iu < uids.size(); iu++) {
        int uid=uids.keyAt(iu);
        numTotalProcs++;
        ProcessState proc=uids.valueAt(iu);
        if (proc.mDurationsTableSize == 0 && proc.mCurState == STATE_NOTHING && proc.mPssTableSize == 0) {
          continue;
        }
        numShownProcs++;
        if (!printedHeader) {
          pw.println();
          pw.println("String_Node_Str");
          printedHeader=true;
        }
        if (activeOnly && !proc.isInUse()) {
          pw.print("String_Node_Str");
          pw.print(procName);
          pw.println("String_Node_Str");
          continue;
        }
        pw.print("String_Node_Str");
        pw.print(procName);
        pw.print("String_Node_Str");
        UserHandle.formatUid(pw,uid);
        pw.print("String_Node_Str");
        pw.print(proc.mDurationsTableSize);
        pw.print("String_Node_Str");
        pw.println("String_Node_Str");
        dumpProcessState(pw,"String_Node_Str",proc,ALL_SCREEN_ADJ,ALL_MEM_ADJ,ALL_PROC_STATES,now);
        dumpProcessPss(pw,"String_Node_Str",proc,ALL_SCREEN_ADJ,ALL_MEM_ADJ,ALL_PROC_STATES);
        if (dumpAll) {
          dumpProcessInternalLocked(pw,"String_Node_Str",proc,dumpAll);
        }
      }
    }
    if (dumpAll) {
      pw.println();
      pw.print("String_Node_Str");
      pw.print(numShownProcs);
      pw.print("String_Node_Str");
      pw.print(numTotalProcs);
      pw.println("String_Node_Str");
    }
    pw.println();
    if (dumpSummary) {
      pw.println("String_Node_Str");
      dumpSummaryLocked(pw,reqPackage,now,activeOnly);
    }
 else {
      dumpTotalsLocked(pw,now);
    }
  }
 else {
    pw.println();
    dumpTotalsLocked(pw,now);
  }
  if (dumpAll) {
    pw.println();
    pw.println("String_Node_Str");
    pw.print("String_Node_Str");
    pw.println(mLongs.size());
    pw.print("String_Node_Str");
    pw.println(mNextLong);
    pw.print("String_Node_Str");
    pw.println(mRunning);
  }
}

Fixed version (ground truth):
public void dumpLocked(PrintWriter pw,String reqPackage,long now,boolean dumpSummary,boolean dumpAll,boolean activeOnly){
  long totalTime=dumpSingleTime(null,null,mMemFactorDurations,mMemFactor,mStartTime,now);
  ArrayMap<String,SparseArray<PackageState>> pkgMap=mPackages.getMap();
  boolean printedHeader=false;
  boolean sepNeeded=false;
  for (int ip=0; ip < pkgMap.size(); ip++) {
    final String pkgName=pkgMap.keyAt(ip);
    final SparseArray<PackageState> uids=pkgMap.valueAt(ip);
    for (int iu=0; iu < uids.size(); iu++) {
      final int uid=uids.keyAt(iu);
      final PackageState pkgState=uids.valueAt(iu);
      final int NPROCS=pkgState.mProcesses.size();
      final int NSRVS=pkgState.mServices.size();
      final boolean pkgMatch=reqPackage == null || reqPackage.equals(pkgName);
      if (!pkgMatch) {
        boolean procMatch=false;
        for (int iproc=0; iproc < NPROCS; iproc++) {
          ProcessState proc=pkgState.mProcesses.valueAt(iproc);
          if (reqPackage.equals(proc.mName)) {
            procMatch=true;
            break;
          }
        }
        if (!procMatch) {
          continue;
        }
      }
      if (NPROCS > 0 || NSRVS > 0) {
        if (!printedHeader) {
          pw.println("String_Node_Str");
          printedHeader=true;
          sepNeeded=true;
        }
        pw.print("String_Node_Str");
        pw.print(pkgName);
        pw.print("String_Node_Str");
        UserHandle.formatUid(pw,uid);
        pw.println("String_Node_Str");
      }
      if (!dumpSummary || dumpAll) {
        for (int iproc=0; iproc < NPROCS; iproc++) {
          ProcessState proc=pkgState.mProcesses.valueAt(iproc);
          if (!pkgMatch && !reqPackage.equals(proc.mName)) {
            continue;
          }
          if (activeOnly && !proc.isInUse()) {
            pw.print("String_Node_Str");
            pw.print(pkgState.mProcesses.keyAt(iproc));
            pw.println("String_Node_Str");
            continue;
          }
          pw.print("String_Node_Str");
          pw.print(pkgState.mProcesses.keyAt(iproc));
          if (proc.mCommonProcess.mMultiPackage) {
            pw.print("String_Node_Str");
          }
 else {
            pw.print("String_Node_Str");
          }
          pw.print(proc.mDurationsTableSize);
          pw.print("String_Node_Str");
          pw.println("String_Node_Str");
          dumpProcessState(pw,"String_Node_Str",proc,ALL_SCREEN_ADJ,ALL_MEM_ADJ,ALL_PROC_STATES,now);
          dumpProcessPss(pw,"String_Node_Str",proc,ALL_SCREEN_ADJ,ALL_MEM_ADJ,ALL_PROC_STATES);
          dumpProcessInternalLocked(pw,"String_Node_Str",proc,dumpAll);
        }
      }
 else {
        ArrayList<ProcessState> procs=new ArrayList<ProcessState>();
        for (int iproc=0; iproc < NPROCS; iproc++) {
          ProcessState proc=pkgState.mProcesses.valueAt(iproc);
          if (!pkgMatch && !reqPackage.equals(proc.mName)) {
            continue;
          }
          if (activeOnly && !proc.isInUse()) {
            continue;
          }
          procs.add(proc);
        }
        dumpProcessSummaryLocked(pw,"String_Node_Str",procs,ALL_SCREEN_ADJ,ALL_MEM_ADJ,NON_CACHED_PROC_STATES,now,totalTime);
      }
      for (int isvc=0; isvc < NSRVS; isvc++) {
        ServiceState svc=pkgState.mServices.valueAt(isvc);
        if (!pkgMatch && !reqPackage.equals(svc.mProcessName)) {
          continue;
        }
        if (activeOnly && !svc.isInUse()) {
          pw.print("String_Node_Str");
          pw.print(pkgState.mServices.keyAt(isvc));
          pw.println("String_Node_Str");
          continue;
        }
        if (dumpAll) {
          pw.print("String_Node_Str");
        }
 else {
          pw.print("String_Node_Str");
        }
        pw.print(pkgState.mServices.keyAt(isvc));
        pw.println("String_Node_Str");
        pw.print("String_Node_Str");
        pw.println(svc.mProcessName);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc,svc.mRunCount,ServiceState.SERVICE_RUN,svc.mRunState,svc.mRunStartTime,now,totalTime,!dumpSummary || dumpAll);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc,svc.mStartedCount,ServiceState.SERVICE_STARTED,svc.mStartedState,svc.mStartedStartTime,now,totalTime,!dumpSummary || dumpAll);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc,svc.mBoundCount,ServiceState.SERVICE_BOUND,svc.mBoundState,svc.mBoundStartTime,now,totalTime,!dumpSummary || dumpAll);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc,svc.mExecCount,ServiceState.SERVICE_EXEC,svc.mExecState,svc.mExecStartTime,now,totalTime,!dumpSummary || dumpAll);
        if (dumpAll) {
          if (svc.mOwner != null) {
            pw.print("String_Node_Str");
            pw.println(svc.mOwner);
          }
          if (svc.mStarted || svc.mRestarting) {
            pw.print("String_Node_Str");
            pw.print(svc.mStarted);
            pw.print("String_Node_Str");
            pw.println(svc.mRestarting);
          }
        }
      }
    }
  }
  ArrayMap<String,SparseArray<ProcessState>> procMap=mProcesses.getMap();
  printedHeader=false;
  int numShownProcs=0, numTotalProcs=0;
  for (int ip=0; ip < procMap.size(); ip++) {
    String procName=procMap.keyAt(ip);
    SparseArray<ProcessState> uids=procMap.valueAt(ip);
    for (int iu=0; iu < uids.size(); iu++) {
      int uid=uids.keyAt(iu);
      numTotalProcs++;
      ProcessState proc=uids.valueAt(iu);
      if (proc.mDurationsTableSize == 0 && proc.mCurState == STATE_NOTHING && proc.mPssTableSize == 0) {
        continue;
      }
      if (!proc.mMultiPackage) {
        continue;
      }
      if (reqPackage != null && !reqPackage.equals(procName) && !reqPackage.equals(proc.mPackage)) {
        continue;
      }
      numShownProcs++;
      if (sepNeeded) {
        pw.println();
      }
      sepNeeded=true;
      if (!printedHeader) {
        pw.println("String_Node_Str");
        printedHeader=true;
      }
      if (activeOnly && !proc.isInUse()) {
        pw.print("String_Node_Str");
        pw.print(procName);
        pw.println("String_Node_Str");
        continue;
      }
      pw.print("String_Node_Str");
      pw.print(procName);
      pw.print("String_Node_Str");
      UserHandle.formatUid(pw,uid);
      pw.print("String_Node_Str");
      pw.print(proc.mDurationsTableSize);
      pw.print("String_Node_Str");
      pw.println("String_Node_Str");
      dumpProcessState(pw,"String_Node_Str",proc,ALL_SCREEN_ADJ,ALL_MEM_ADJ,ALL_PROC_STATES,now);
      dumpProcessPss(pw,"String_Node_Str",proc,ALL_SCREEN_ADJ,ALL_MEM_ADJ,ALL_PROC_STATES);
      dumpProcessInternalLocked(pw,"String_Node_Str",proc,dumpAll);
    }
  }
  if (dumpAll) {
    pw.println();
    pw.print("String_Node_Str");
    pw.print(numShownProcs);
    pw.print("String_Node_Str");
    pw.print(numTotalProcs);
    pw.println("String_Node_Str");
  }
  if (sepNeeded) {
    pw.println();
  }
  if (dumpSummary) {
    pw.println("String_Node_Str");
    dumpSummaryLocked(pw,reqPackage,now,activeOnly);
  }
 else {
    dumpTotalsLocked(pw,now);
  }
  if (dumpAll) {
    pw.println();
    pw.println("String_Node_Str");
    pw.print("String_Node_Str");
    pw.println(mLongs.size());
    pw.print("String_Node_Str");
    pw.println(mNextLong);
    pw.print("String_Node_Str");
    pw.println(mRunning);
  }
}