Program: 1103
Project: 1103
Buggy source:
public void dumpLocked(PrintWriter pw,String reqPackage,long now,boolean dumpSummary,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 (!dumpSummary || 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);
          dumpProcessInternalLocked(pw,"String_Node_Str",proc,dumpAll);
        }
      }
 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);
        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) {
          pw.print("String_Node_Str");
          pw.println(svc.mActive);
        }
      }
    }
  }
  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;
        }
        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);
    }
 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;
  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);
  }
}