Program: 1631
Project: 1631
Buggy source:
@SuppressWarnings("String_Node_Str") public void dumpCheckinLocked(PrintWriter pw,List<ApplicationInfo> apps,boolean isUnpluggedOnly){
  prepareForDumpLocked();
  long now=getHistoryBaseTime() + SystemClock.elapsedRealtime();
  final HistoryItem rec=new HistoryItem();
  if (startIteratingHistoryLocked()) {
    HistoryPrinter hprinter=new HistoryPrinter();
    while (getNextHistoryLocked(rec)) {
      pw.print(BATTERY_STATS_CHECKIN_VERSION);
      pw.print(',');
      pw.print(0);
      pw.print(',');
      pw.print(HISTORY_DATA);
      pw.print(',');
      hprinter.printNextItemCheckin(pw,rec,now);
      pw.println();
    }
    finishIteratingHistoryLocked();
  }
  if (apps != null) {
    SparseArray<ArrayList<String>> uids=new SparseArray<ArrayList<String>>();
    for (int i=0; i < apps.size(); i++) {
      ApplicationInfo ai=apps.get(i);
      ArrayList<String> pkgs=uids.get(ai.uid);
      if (pkgs == null) {
        pkgs=new ArrayList<String>();
        uids.put(ai.uid,pkgs);
      }
      pkgs.add(ai.packageName);
    }
    SparseArray<? extends Uid> uidStats=getUidStats();
    final int NU=uidStats.size();
    String[] lineArgs=new String[2];
    for (int i=0; i < NU; i++) {
      int uid=uidStats.keyAt(i);
      ArrayList<String> pkgs=uids.get(uid);
      if (pkgs != null) {
        for (int j=0; j < pkgs.size(); j++) {
          lineArgs[0]=Integer.toString(uid);
          lineArgs[1]=pkgs.get(j);
          dumpLine(pw,0,"String_Node_Str",UID_DATA,(Object[])lineArgs);
        }
      }
    }
  }
  if (isUnpluggedOnly) {
    dumpCheckinLocked(pw,STATS_SINCE_UNPLUGGED,-1);
  }
 else {
    dumpCheckinLocked(pw,STATS_SINCE_CHARGED,-1);
    dumpCheckinLocked(pw,STATS_SINCE_UNPLUGGED,-1);
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") public void dumpCheckinLocked(PrintWriter pw,List<ApplicationInfo> apps,boolean isUnpluggedOnly,boolean includeHistory){
  prepareForDumpLocked();
  long now=getHistoryBaseTime() + SystemClock.elapsedRealtime();
  if (includeHistory) {
    final HistoryItem rec=new HistoryItem();
    if (startIteratingHistoryLocked()) {
      HistoryPrinter hprinter=new HistoryPrinter();
      while (getNextHistoryLocked(rec)) {
        pw.print(BATTERY_STATS_CHECKIN_VERSION);
        pw.print(',');
        pw.print(0);
        pw.print(',');
        pw.print(HISTORY_DATA);
        pw.print(',');
        hprinter.printNextItemCheckin(pw,rec,now);
        pw.println();
      }
      finishIteratingHistoryLocked();
    }
  }
  if (apps != null) {
    SparseArray<ArrayList<String>> uids=new SparseArray<ArrayList<String>>();
    for (int i=0; i < apps.size(); i++) {
      ApplicationInfo ai=apps.get(i);
      ArrayList<String> pkgs=uids.get(ai.uid);
      if (pkgs == null) {
        pkgs=new ArrayList<String>();
        uids.put(ai.uid,pkgs);
      }
      pkgs.add(ai.packageName);
    }
    SparseArray<? extends Uid> uidStats=getUidStats();
    final int NU=uidStats.size();
    String[] lineArgs=new String[2];
    for (int i=0; i < NU; i++) {
      int uid=uidStats.keyAt(i);
      ArrayList<String> pkgs=uids.get(uid);
      if (pkgs != null) {
        for (int j=0; j < pkgs.size(); j++) {
          lineArgs[0]=Integer.toString(uid);
          lineArgs[1]=pkgs.get(j);
          dumpLine(pw,0,"String_Node_Str",UID_DATA,(Object[])lineArgs);
        }
      }
    }
  }
  if (isUnpluggedOnly) {
    dumpCheckinLocked(pw,STATS_SINCE_UNPLUGGED,-1);
  }
 else {
    dumpCheckinLocked(pw,STATS_SINCE_CHARGED,-1);
    dumpCheckinLocked(pw,STATS_SINCE_UNPLUGGED,-1);
  }
}