Program: 1643
Project: 1643
Buggy source:
public void dumpLocked(PrintWriter pw,String reqPackage,long now,boolean dumpAll){
  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 (dumpAll) {
        for (int iproc=0; iproc < NPROCS; iproc++) {
          ProcessState proc=pkgState.mProcesses.valueAt(iproc);
          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);
          if (dumpAll) {
            pw.print("String_Node_Str");
            pw.println(proc.mNumStartedServices);
          }
        }
      }
 else {
        ArrayList<ProcessState> procs=new ArrayList<ProcessState>();
        for (int iproc=0; iproc < NPROCS; iproc++) {
          procs.add(pkgState.mProcesses.valueAt(iproc));
        }
        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++) {
        if (dumpAll) {
          pw.print("String_Node_Str");
        }
 else {
          pw.print("String_Node_Str");
        }
        pw.print(pkgState.mServices.keyAt(isvc));
        pw.println("String_Node_Str");
        ServiceState svc=pkgState.mServices.valueAt(isvc);
        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,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,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,dumpAll);
      }
    }
  }
  if (reqPackage == null) {
    ArrayMap<String,SparseArray<ProcessState>> procMap=mProcesses.getMap();
    printedHeader=false;
    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);
        ProcessState proc=uids.valueAt(iu);
        if (proc.mDurationsTableSize == 0 && proc.mCurState == STATE_NOTHING && proc.mPssTableSize == 0) {
          continue;
        }
        if (!printedHeader) {
          pw.println("String_Node_Str");
          printedHeader=true;
        }
        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);
      }
    }
    pw.println();
    pw.println("String_Node_Str");
    dumpSummaryLocked(pw,reqPackage,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 dumpAll){
  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 (dumpAll) {
        for (int iproc=0; iproc < NPROCS; iproc++) {
          ProcessState proc=pkgState.mProcesses.valueAt(iproc);
          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);
          if (dumpAll) {
            pw.print("String_Node_Str");
            pw.println(proc.mNumStartedServices);
          }
        }
      }
 else {
        ArrayList<ProcessState> procs=new ArrayList<ProcessState>();
        for (int iproc=0; iproc < NPROCS; iproc++) {
          procs.add(pkgState.mProcesses.valueAt(iproc));
        }
        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++) {
        if (dumpAll) {
          pw.print("String_Node_Str");
        }
 else {
          pw.print("String_Node_Str");
        }
        pw.print(pkgState.mServices.keyAt(isvc));
        pw.println("String_Node_Str");
        ServiceState svc=pkgState.mServices.valueAt(isvc);
        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,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,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,dumpAll);
      }
    }
  }
  if (reqPackage == null) {
    ArrayMap<String,SparseArray<ProcessState>> procMap=mProcesses.getMap();
    printedHeader=false;
    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);
        ProcessState proc=uids.valueAt(iu);
        if (proc.mDurationsTableSize == 0 && proc.mCurState == STATE_NOTHING && proc.mPssTableSize == 0) {
          continue;
        }
        if (!printedHeader) {
          pw.println();
          pw.println("String_Node_Str");
          printedHeader=true;
        }
        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);
      }
    }
    pw.println();
    pw.println("String_Node_Str");
    dumpSummaryLocked(pw,reqPackage,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);
  }
}