Program: 1780
Project: 1780
Buggy source:
public void dump(FileDescriptor fd,PrintWriter pw,String[] args){
  final long now=SystemClock.uptimeMillis();
  boolean isCheckin=false;
  boolean isCompact=false;
  boolean isCsv=false;
  boolean currentOnly=false;
  boolean dumpDetails=false;
  boolean dumpAll=false;
  String reqPackage=null;
  boolean csvSepScreenStats=false;
  int[] csvScreenStats=new int[]{ADJ_SCREEN_OFF,ADJ_SCREEN_ON};
  boolean csvSepMemStats=false;
  int[] csvMemStats=new int[]{ADJ_MEM_FACTOR_CRITICAL};
  boolean csvSepProcStats=true;
  int[] csvProcStats=new int[]{STATE_PERSISTENT,STATE_TOP,STATE_IMPORTANT_FOREGROUND,STATE_IMPORTANT_BACKGROUND,STATE_BACKUP,STATE_HEAVY_WEIGHT,STATE_SERVICE,STATE_RECEIVER,STATE_HOME,STATE_LAST_ACTIVITY,STATE_CACHED_ACTIVITY,STATE_CACHED_ACTIVITY_CLIENT,STATE_CACHED_EMPTY};
  if (args != null) {
    for (int i=0; i < args.length; i++) {
      String arg=args[i];
      if ("String_Node_Str".equals(arg)) {
        isCheckin=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        isCompact=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        isCsv=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        i++;
        if (i >= args.length) {
          pw.println("String_Node_Str");
          dumpHelp(pw);
          return;
        }
        boolean[] sep=new boolean[1];
        String[] error=new String[1];
        csvScreenStats=parseStateList(ADJ_SCREEN_NAMES_CSV,ADJ_SCREEN_MOD,args[i],sep,error);
        if (csvScreenStats == null) {
          pw.println("String_Node_Str" + args[i] + "String_Node_Str"+ error[0]);
          dumpHelp(pw);
          return;
        }
        csvSepScreenStats=sep[0];
      }
 else       if ("String_Node_Str".equals(arg)) {
        i++;
        if (i >= args.length) {
          pw.println("String_Node_Str");
          dumpHelp(pw);
          return;
        }
        boolean[] sep=new boolean[1];
        String[] error=new String[1];
        csvMemStats=parseStateList(ADJ_MEM_NAMES_CSV,1,args[i],sep,error);
        if (csvMemStats == null) {
          pw.println("String_Node_Str" + args[i] + "String_Node_Str"+ error[0]);
          dumpHelp(pw);
          return;
        }
        csvSepMemStats=sep[0];
      }
 else       if ("String_Node_Str".equals(arg)) {
        i++;
        if (i >= args.length) {
          pw.println("String_Node_Str");
          dumpHelp(pw);
          return;
        }
        boolean[] sep=new boolean[1];
        String[] error=new String[1];
        csvProcStats=parseStateList(STATE_NAMES_CSV,1,args[i],sep,error);
        if (csvProcStats == null) {
          pw.println("String_Node_Str" + args[i] + "String_Node_Str"+ error[0]);
          dumpHelp(pw);
          return;
        }
        csvSepProcStats=sep[0];
      }
 else       if ("String_Node_Str".equals(arg)) {
        dumpDetails=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        currentOnly=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        mState.mFlags|=State.FLAG_COMPLETE;
        mState.writeStateLocked(true,true);
        pw.println("String_Node_Str");
        return;
      }
 else       if ("String_Node_Str".equals(arg)) {
        writeStateSyncLocked();
        pw.println("String_Node_Str");
        return;
      }
 else       if ("String_Node_Str".equals(arg)) {
        readLocked();
        pw.println("String_Node_Str");
        return;
      }
 else       if ("String_Node_Str".equals(arg)) {
        dumpHelp(pw);
        return;
      }
 else       if ("String_Node_Str".equals(arg)) {
        dumpDetails=true;
        dumpAll=true;
      }
 else       if (arg.length() > 0 && arg.charAt(0) == '-') {
        pw.println("String_Node_Str" + arg);
        dumpHelp(pw);
        return;
      }
 else {
        try {
          IPackageManager pm=AppGlobals.getPackageManager();
          if (pm.getPackageUid(arg,UserHandle.getCallingUserId()) >= 0) {
            reqPackage=arg;
            dumpDetails=true;
          }
        }
 catch (        RemoteException e) {
        }
        if (reqPackage == null) {
          pw.println("String_Node_Str" + arg);
          dumpHelp(pw);
          return;
        }
      }
    }
  }
  if (isCsv) {
    pw.print("String_Node_Str");
    if (!csvSepScreenStats) {
      for (int i=0; i < csvScreenStats.length; i++) {
        pw.print("String_Node_Str");
        printScreenLabelCsv(pw,csvScreenStats[i]);
      }
    }
    if (!csvSepMemStats) {
      for (int i=0; i < csvMemStats.length; i++) {
        pw.print("String_Node_Str");
        printMemLabelCsv(pw,csvMemStats[i]);
      }
    }
    if (!csvSepProcStats) {
      for (int i=0; i < csvProcStats.length; i++) {
        pw.print("String_Node_Str");
        pw.print(STATE_NAMES_CSV[csvProcStats[i]]);
      }
    }
    pw.println();
synchronized (mLock) {
      dumpFilteredProcessesCsvLocked(pw,null,csvSepScreenStats,csvScreenStats,csvSepMemStats,csvMemStats,csvSepProcStats,csvProcStats,now,reqPackage);
    }
    return;
  }
  boolean sepNeeded=false;
  if (!currentOnly || isCheckin) {
    mWriteLock.lock();
    try {
      ArrayList<String> files=getCommittedFiles(0,!isCheckin);
      if (files != null) {
        for (int i=0; i < files.size(); i++) {
          if (DEBUG)           Slog.d(TAG,"String_Node_Str" + files.get(i));
          try {
            State state=new State(files.get(i));
            if (state.mReadError != null) {
              pw.print("String_Node_Str");
              pw.print(files.get(i));
              pw.print("String_Node_Str");
              pw.println(state.mReadError);
              if (DEBUG)               Slog.d(TAG,"String_Node_Str" + files.get(i));
              (new File(files.get(i))).delete();
              continue;
            }
            String fileStr=state.mFile.getBaseFile().getPath();
            boolean checkedIn=fileStr.endsWith(STATE_FILE_CHECKIN_SUFFIX);
            if (isCheckin || isCompact) {
              state.dumpCheckinLocked(pw,reqPackage);
            }
 else {
              if (sepNeeded) {
                pw.println();
              }
 else {
                sepNeeded=true;
              }
              pw.print("String_Node_Str");
              pw.print(state.mTimePeriodStartClockStr);
              if (checkedIn)               pw.print("String_Node_Str");
              pw.println("String_Node_Str");
              if (dumpDetails) {
                state.dumpLocked(pw,reqPackage,now,dumpAll);
              }
 else {
                state.dumpSummaryLocked(pw,reqPackage,now);
              }
            }
            if (isCheckin) {
              state.mFile.getBaseFile().renameTo(new File(fileStr + STATE_FILE_CHECKIN_SUFFIX));
            }
          }
 catch (          Throwable e) {
            pw.print("String_Node_Str");
            pw.println(files.get(i));
            e.printStackTrace(pw);
          }
        }
      }
    }
  finally {
      mWriteLock.unlock();
    }
  }
  if (!isCheckin) {
synchronized (mLock) {
      if (isCompact) {
        mState.dumpCheckinLocked(pw,reqPackage);
      }
 else {
        if (sepNeeded) {
          pw.println();
          pw.println("String_Node_Str");
        }
        if (dumpDetails) {
          mState.dumpLocked(pw,reqPackage,now,dumpAll);
        }
 else {
          mState.dumpSummaryLocked(pw,reqPackage,now);
        }
      }
    }
  }
}

Fixed version (ground truth):
public void dump(FileDescriptor fd,PrintWriter pw,String[] args){
  final long now=SystemClock.uptimeMillis();
  boolean isCheckin=false;
  boolean isCompact=false;
  boolean isCsv=false;
  boolean currentOnly=false;
  boolean dumpDetails=false;
  boolean dumpAll=false;
  String reqPackage=null;
  boolean csvSepScreenStats=false;
  int[] csvScreenStats=new int[]{ADJ_SCREEN_OFF,ADJ_SCREEN_ON};
  boolean csvSepMemStats=false;
  int[] csvMemStats=new int[]{ADJ_MEM_FACTOR_CRITICAL};
  boolean csvSepProcStats=true;
  int[] csvProcStats=ALL_PROC_STATES;
  if (args != null) {
    for (int i=0; i < args.length; i++) {
      String arg=args[i];
      if ("String_Node_Str".equals(arg)) {
        isCheckin=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        isCompact=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        isCsv=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        i++;
        if (i >= args.length) {
          pw.println("String_Node_Str");
          dumpHelp(pw);
          return;
        }
        boolean[] sep=new boolean[1];
        String[] error=new String[1];
        csvScreenStats=parseStateList(ADJ_SCREEN_NAMES_CSV,ADJ_SCREEN_MOD,args[i],sep,error);
        if (csvScreenStats == null) {
          pw.println("String_Node_Str" + args[i] + "String_Node_Str"+ error[0]);
          dumpHelp(pw);
          return;
        }
        csvSepScreenStats=sep[0];
      }
 else       if ("String_Node_Str".equals(arg)) {
        i++;
        if (i >= args.length) {
          pw.println("String_Node_Str");
          dumpHelp(pw);
          return;
        }
        boolean[] sep=new boolean[1];
        String[] error=new String[1];
        csvMemStats=parseStateList(ADJ_MEM_NAMES_CSV,1,args[i],sep,error);
        if (csvMemStats == null) {
          pw.println("String_Node_Str" + args[i] + "String_Node_Str"+ error[0]);
          dumpHelp(pw);
          return;
        }
        csvSepMemStats=sep[0];
      }
 else       if ("String_Node_Str".equals(arg)) {
        i++;
        if (i >= args.length) {
          pw.println("String_Node_Str");
          dumpHelp(pw);
          return;
        }
        boolean[] sep=new boolean[1];
        String[] error=new String[1];
        csvProcStats=parseStateList(STATE_NAMES_CSV,1,args[i],sep,error);
        if (csvProcStats == null) {
          pw.println("String_Node_Str" + args[i] + "String_Node_Str"+ error[0]);
          dumpHelp(pw);
          return;
        }
        csvSepProcStats=sep[0];
      }
 else       if ("String_Node_Str".equals(arg)) {
        dumpDetails=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        currentOnly=true;
      }
 else       if ("String_Node_Str".equals(arg)) {
        mState.mFlags|=State.FLAG_COMPLETE;
        mState.writeStateLocked(true,true);
        pw.println("String_Node_Str");
        return;
      }
 else       if ("String_Node_Str".equals(arg)) {
        writeStateSyncLocked();
        pw.println("String_Node_Str");
        return;
      }
 else       if ("String_Node_Str".equals(arg)) {
        readLocked();
        pw.println("String_Node_Str");
        return;
      }
 else       if ("String_Node_Str".equals(arg)) {
        dumpHelp(pw);
        return;
      }
 else       if ("String_Node_Str".equals(arg)) {
        dumpDetails=true;
        dumpAll=true;
      }
 else       if (arg.length() > 0 && arg.charAt(0) == '-') {
        pw.println("String_Node_Str" + arg);
        dumpHelp(pw);
        return;
      }
 else {
        try {
          IPackageManager pm=AppGlobals.getPackageManager();
          if (pm.getPackageUid(arg,UserHandle.getCallingUserId()) >= 0) {
            reqPackage=arg;
            dumpDetails=true;
          }
        }
 catch (        RemoteException e) {
        }
        if (reqPackage == null) {
          pw.println("String_Node_Str" + arg);
          dumpHelp(pw);
          return;
        }
      }
    }
  }
  if (isCsv) {
    pw.print("String_Node_Str");
    if (!csvSepScreenStats) {
      for (int i=0; i < csvScreenStats.length; i++) {
        pw.print("String_Node_Str");
        printScreenLabelCsv(pw,csvScreenStats[i]);
      }
    }
    if (!csvSepMemStats) {
      for (int i=0; i < csvMemStats.length; i++) {
        pw.print("String_Node_Str");
        printMemLabelCsv(pw,csvMemStats[i]);
      }
    }
    if (!csvSepProcStats) {
      for (int i=0; i < csvProcStats.length; i++) {
        pw.print("String_Node_Str");
        pw.print(STATE_NAMES_CSV[csvProcStats[i]]);
      }
    }
    pw.println();
synchronized (mLock) {
      dumpFilteredProcessesCsvLocked(pw,null,csvSepScreenStats,csvScreenStats,csvSepMemStats,csvMemStats,csvSepProcStats,csvProcStats,now,reqPackage);
    }
    return;
  }
  boolean sepNeeded=false;
  if (!currentOnly || isCheckin) {
    mWriteLock.lock();
    try {
      ArrayList<String> files=getCommittedFiles(0,!isCheckin);
      if (files != null) {
        for (int i=0; i < files.size(); i++) {
          if (DEBUG)           Slog.d(TAG,"String_Node_Str" + files.get(i));
          try {
            State state=new State(files.get(i));
            if (state.mReadError != null) {
              pw.print("String_Node_Str");
              pw.print(files.get(i));
              pw.print("String_Node_Str");
              pw.println(state.mReadError);
              if (DEBUG)               Slog.d(TAG,"String_Node_Str" + files.get(i));
              (new File(files.get(i))).delete();
              continue;
            }
            String fileStr=state.mFile.getBaseFile().getPath();
            boolean checkedIn=fileStr.endsWith(STATE_FILE_CHECKIN_SUFFIX);
            if (isCheckin || isCompact) {
              state.dumpCheckinLocked(pw,reqPackage);
            }
 else {
              if (sepNeeded) {
                pw.println();
              }
 else {
                sepNeeded=true;
              }
              pw.print("String_Node_Str");
              pw.print(state.mTimePeriodStartClockStr);
              if (checkedIn)               pw.print("String_Node_Str");
              pw.println("String_Node_Str");
              if (dumpDetails) {
                state.dumpLocked(pw,reqPackage,now,dumpAll);
              }
 else {
                state.dumpSummaryLocked(pw,reqPackage,now);
              }
            }
            if (isCheckin) {
              state.mFile.getBaseFile().renameTo(new File(fileStr + STATE_FILE_CHECKIN_SUFFIX));
            }
          }
 catch (          Throwable e) {
            pw.print("String_Node_Str");
            pw.println(files.get(i));
            e.printStackTrace(pw);
          }
        }
      }
    }
  finally {
      mWriteLock.unlock();
    }
  }
  if (!isCheckin) {
synchronized (mLock) {
      if (isCompact) {
        mState.dumpCheckinLocked(pw,reqPackage);
      }
 else {
        if (sepNeeded) {
          pw.println();
          pw.println("String_Node_Str");
        }
        if (dumpDetails) {
          mState.dumpLocked(pw,reqPackage,now,dumpAll);
        }
 else {
          mState.dumpSummaryLocked(pw,reqPackage,now);
        }
      }
    }
  }
}