Program: 1777
Project: 1777
Buggy source:
void dumpLocked(PrintWriter pw,String reqPackage,long now,boolean dumpAll){
  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");
      }
      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);
      }
      for (int isvc=0; isvc < NSRVS; isvc++) {
        pw.print("String_Node_Str");
        pw.print(pkgState.mServices.keyAt(isvc));
        pw.println("String_Node_Str");
        ServiceState svc=pkgState.mServices.valueAt(isvc);
        if (svc.mStartedCount != 0) {
          pw.print("String_Node_Str");
          pw.print(svc.mStartedCount);
          pw.println("String_Node_Str");
          dumpSingleTime(pw,"String_Node_Str",svc.mStartedDurations,svc.mStartedState,svc.mStartedStartTime,now);
        }
        if (svc.mBoundCount != 0) {
          pw.print("String_Node_Str");
          pw.print(svc.mBoundCount);
          pw.println("String_Node_Str");
          dumpSingleTime(pw,"String_Node_Str",svc.mBoundDurations,svc.mBoundState,svc.mBoundStartTime,now);
        }
        if (svc.mExecCount != 0) {
          pw.print("String_Node_Str");
          pw.print(svc.mExecCount);
          pw.println("String_Node_Str");
          dumpSingleTime(pw,"String_Node_Str",svc.mExecDurations,svc.mExecState,svc.mExecStartTime,now);
        }
      }
    }
  }
  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);
  }
  if (dumpAll) {
    pw.println();
    pw.println("String_Node_Str");
    pw.print("String_Node_Str");
    pw.println(mFile.getBaseFile());
    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):
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);
        }
      }
 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.mStartedCount,svc.mStartedDurations,svc.mStartedState,svc.mStartedStartTime,now,totalTime,dumpAll);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc.mBoundCount,svc.mBoundDurations,svc.mBoundState,svc.mBoundStartTime,now,totalTime,dumpAll);
        dumpServiceStats(pw,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",svc.mExecCount,svc.mExecDurations,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(mFile.getBaseFile());
    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);
  }
}