Program: 195618
Project: 195618
Buggy source:
public void printNextItem(PrintWriter pw,HistoryItem rec,long baseTime,boolean checkin,boolean verbose){
  if (!checkin) {
    pw.print("String_Node_Str");
    TimeUtils.formatDuration(rec.time - baseTime,pw,TimeUtils.HUNDRED_DAY_FIELD_LEN);
    pw.print("String_Node_Str");
    pw.print(rec.numReadInts);
    pw.print("String_Node_Str");
  }
 else {
    pw.print(BATTERY_STATS_CHECKIN_VERSION);
    pw.print(',');
    pw.print(HISTORY_DATA);
    pw.print(',');
    if (lastTime < 0) {
      pw.print(rec.time - baseTime);
    }
 else {
      pw.print(rec.time - lastTime);
    }
    lastTime=rec.time;
  }
  if (rec.cmd == HistoryItem.CMD_START) {
    if (checkin) {
      pw.print("String_Node_Str");
    }
    pw.println("String_Node_Str");
    reset();
  }
 else   if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) {
    if (checkin) {
      pw.print("String_Node_Str");
    }
    if (rec.cmd == HistoryItem.CMD_RESET) {
      pw.print("String_Node_Str");
      reset();
    }
    pw.print("String_Node_Str");
    if (checkin) {
      pw.println(rec.currentTime);
    }
 else {
      pw.print("String_Node_Str");
      pw.println(DateFormat.format("String_Node_Str",rec.currentTime).toString());
    }
  }
 else   if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
    if (checkin) {
      pw.print("String_Node_Str");
    }
    pw.println("String_Node_Str");
  }
 else {
    if (!checkin) {
      if (rec.batteryLevel < 10)       pw.print("String_Node_Str");
 else       if (rec.batteryLevel < 100)       pw.print("String_Node_Str");
      pw.print(rec.batteryLevel);
      if (verbose) {
        pw.print("String_Node_Str");
        if (rec.states < 0)         ;
 else         if (rec.states < 0x10)         pw.print("String_Node_Str");
 else         if (rec.states < 0x100)         pw.print("String_Node_Str");
 else         if (rec.states < 0x1000)         pw.print("String_Node_Str");
 else         if (rec.states < 0x10000)         pw.print("String_Node_Str");
 else         if (rec.states < 0x100000)         pw.print("String_Node_Str");
 else         if (rec.states < 0x1000000)         pw.print("String_Node_Str");
 else         if (rec.states < 0x10000000)         pw.print("String_Node_Str");
        pw.print(Integer.toHexString(rec.states));
      }
    }
 else {
      if (oldLevel != rec.batteryLevel) {
        oldLevel=rec.batteryLevel;
        pw.print("String_Node_Str");
        pw.print(rec.batteryLevel);
      }
    }
    if (oldStatus != rec.batteryStatus) {
      oldStatus=rec.batteryStatus;
      pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
switch (oldStatus) {
case BatteryManager.BATTERY_STATUS_UNKNOWN:
        pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
      break;
case BatteryManager.BATTERY_STATUS_CHARGING:
    pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
  break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_STATUS_FULL:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
default :
pw.print(oldStatus);
break;
}
}
if (oldHealth != rec.batteryHealth) {
oldHealth=rec.batteryHealth;
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
switch (oldHealth) {
case BatteryManager.BATTERY_HEALTH_UNKNOWN:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_GOOD:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_OVERHEAT:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_DEAD:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_COLD:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
default :
pw.print(oldHealth);
break;
}
}
if (oldPlug != rec.batteryPlugType) {
oldPlug=rec.batteryPlugType;
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
switch (oldPlug) {
case 0:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_PLUGGED_AC:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_PLUGGED_USB:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_PLUGGED_WIRELESS:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
default :
pw.print(oldPlug);
break;
}
}
if (oldTemp != rec.batteryTemperature) {
oldTemp=rec.batteryTemperature;
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
pw.print(oldTemp);
}
if (oldVolt != rec.batteryVoltage) {
oldVolt=rec.batteryVoltage;
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
pw.print(oldVolt);
}
printBitDescriptions(pw,oldState,rec.states,rec.wakelockTag,HISTORY_STATE_DESCRIPTIONS,!checkin);
printBitDescriptions(pw,oldState2,rec.states2,null,HISTORY_STATE2_DESCRIPTIONS,!checkin);
if (rec.wakeReasonTag != null) {
if (checkin) {
pw.print("String_Node_Str");
pw.print(rec.wakeReasonTag.poolIdx);
}
 else {
pw.print("String_Node_Str");
pw.print(rec.wakeReasonTag.uid);
pw.print("String_Node_Str");
pw.print(rec.wakeReasonTag.string);
pw.print("String_Node_Str");
}
}
if (rec.eventCode != HistoryItem.EVENT_NONE) {
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
if ((rec.eventCode & HistoryItem.EVENT_FLAG_START) != 0) {
pw.print("String_Node_Str");
}
 else if ((rec.eventCode & HistoryItem.EVENT_FLAG_FINISH) != 0) {
pw.print("String_Node_Str");
}
String[] eventNames=checkin ? HISTORY_EVENT_CHECKIN_NAMES : HISTORY_EVENT_NAMES;
int idx=rec.eventCode & ~(HistoryItem.EVENT_FLAG_START | HistoryItem.EVENT_FLAG_FINISH);
if (idx >= 0 && idx < eventNames.length) {
pw.print(eventNames[idx]);
}
 else {
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
pw.print(idx);
}
pw.print("String_Node_Str");
if (checkin) {
pw.print(rec.eventTag.poolIdx);
}
 else {
UserHandle.formatUid(pw,rec.eventTag.uid);
pw.print("String_Node_Str");
pw.print(rec.eventTag.string);
pw.print("String_Node_Str");
}
}
pw.println();
oldState=rec.states;
oldState2=rec.states2;
}
}

Fixed version (ground truth):
public void printNextItem(PrintWriter pw,HistoryItem rec,long baseTime,boolean checkin,boolean verbose){
  if (!checkin) {
    pw.print("String_Node_Str");
    TimeUtils.formatDuration(rec.time - baseTime,pw,TimeUtils.HUNDRED_DAY_FIELD_LEN);
    pw.print("String_Node_Str");
    pw.print(rec.numReadInts);
    pw.print("String_Node_Str");
  }
 else {
    pw.print(BATTERY_STATS_CHECKIN_VERSION);
    pw.print(',');
    pw.print(HISTORY_DATA);
    pw.print(',');
    if (lastTime < 0) {
      pw.print(rec.time - baseTime);
    }
 else {
      pw.print(rec.time - lastTime);
    }
    lastTime=rec.time;
  }
  if (rec.cmd == HistoryItem.CMD_START) {
    if (checkin) {
      pw.print("String_Node_Str");
    }
    pw.println("String_Node_Str");
    reset();
  }
 else   if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) {
    if (checkin) {
      pw.print("String_Node_Str");
    }
    if (rec.cmd == HistoryItem.CMD_RESET) {
      pw.print("String_Node_Str");
      reset();
    }
    pw.print("String_Node_Str");
    if (checkin) {
      pw.println(rec.currentTime);
    }
 else {
      pw.print("String_Node_Str");
      pw.println(DateFormat.format("String_Node_Str",rec.currentTime).toString());
    }
  }
 else   if (rec.cmd == HistoryItem.CMD_SHUTDOWN) {
    if (checkin) {
      pw.print("String_Node_Str");
    }
    pw.println("String_Node_Str");
  }
 else   if (rec.cmd == HistoryItem.CMD_OVERFLOW) {
    if (checkin) {
      pw.print("String_Node_Str");
    }
    pw.println("String_Node_Str");
  }
 else {
    if (!checkin) {
      if (rec.batteryLevel < 10)       pw.print("String_Node_Str");
 else       if (rec.batteryLevel < 100)       pw.print("String_Node_Str");
      pw.print(rec.batteryLevel);
      if (verbose) {
        pw.print("String_Node_Str");
        if (rec.states < 0)         ;
 else         if (rec.states < 0x10)         pw.print("String_Node_Str");
 else         if (rec.states < 0x100)         pw.print("String_Node_Str");
 else         if (rec.states < 0x1000)         pw.print("String_Node_Str");
 else         if (rec.states < 0x10000)         pw.print("String_Node_Str");
 else         if (rec.states < 0x100000)         pw.print("String_Node_Str");
 else         if (rec.states < 0x1000000)         pw.print("String_Node_Str");
 else         if (rec.states < 0x10000000)         pw.print("String_Node_Str");
        pw.print(Integer.toHexString(rec.states));
      }
    }
 else {
      if (oldLevel != rec.batteryLevel) {
        oldLevel=rec.batteryLevel;
        pw.print("String_Node_Str");
        pw.print(rec.batteryLevel);
      }
    }
    if (oldStatus != rec.batteryStatus) {
      oldStatus=rec.batteryStatus;
      pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
switch (oldStatus) {
case BatteryManager.BATTERY_STATUS_UNKNOWN:
        pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
      break;
case BatteryManager.BATTERY_STATUS_CHARGING:
    pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
  break;
case BatteryManager.BATTERY_STATUS_DISCHARGING:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_STATUS_FULL:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
default :
pw.print(oldStatus);
break;
}
}
if (oldHealth != rec.batteryHealth) {
oldHealth=rec.batteryHealth;
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
switch (oldHealth) {
case BatteryManager.BATTERY_HEALTH_UNKNOWN:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_GOOD:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_OVERHEAT:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_DEAD:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_HEALTH_COLD:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
default :
pw.print(oldHealth);
break;
}
}
if (oldPlug != rec.batteryPlugType) {
oldPlug=rec.batteryPlugType;
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
switch (oldPlug) {
case 0:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_PLUGGED_AC:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_PLUGGED_USB:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
case BatteryManager.BATTERY_PLUGGED_WIRELESS:
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
break;
default :
pw.print(oldPlug);
break;
}
}
if (oldTemp != rec.batteryTemperature) {
oldTemp=rec.batteryTemperature;
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
pw.print(oldTemp);
}
if (oldVolt != rec.batteryVoltage) {
oldVolt=rec.batteryVoltage;
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
pw.print(oldVolt);
}
printBitDescriptions(pw,oldState,rec.states,rec.wakelockTag,HISTORY_STATE_DESCRIPTIONS,!checkin);
printBitDescriptions(pw,oldState2,rec.states2,null,HISTORY_STATE2_DESCRIPTIONS,!checkin);
if (rec.wakeReasonTag != null) {
if (checkin) {
pw.print("String_Node_Str");
pw.print(rec.wakeReasonTag.poolIdx);
}
 else {
pw.print("String_Node_Str");
pw.print(rec.wakeReasonTag.uid);
pw.print("String_Node_Str");
pw.print(rec.wakeReasonTag.string);
pw.print("String_Node_Str");
}
}
if (rec.eventCode != HistoryItem.EVENT_NONE) {
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
if ((rec.eventCode & HistoryItem.EVENT_FLAG_START) != 0) {
pw.print("String_Node_Str");
}
 else if ((rec.eventCode & HistoryItem.EVENT_FLAG_FINISH) != 0) {
pw.print("String_Node_Str");
}
String[] eventNames=checkin ? HISTORY_EVENT_CHECKIN_NAMES : HISTORY_EVENT_NAMES;
int idx=rec.eventCode & ~(HistoryItem.EVENT_FLAG_START | HistoryItem.EVENT_FLAG_FINISH);
if (idx >= 0 && idx < eventNames.length) {
pw.print(eventNames[idx]);
}
 else {
pw.print(checkin ? "String_Node_Str" : "String_Node_Str");
pw.print(idx);
}
pw.print("String_Node_Str");
if (checkin) {
pw.print(rec.eventTag.poolIdx);
}
 else {
UserHandle.formatUid(pw,rec.eventTag.uid);
pw.print("String_Node_Str");
pw.print(rec.eventTag.string);
pw.print("String_Node_Str");
}
}
pw.println();
oldState=rec.states;
oldState2=rec.states2;
}
}