Program: 106064
Project: 106064
Buggy source:
@Override public void saveUsageRecords(List<UsageVO> usageRecords){
  TransactionLegacy txn=TransactionLegacy.currentTxn();
  try {
    txn.start();
    String sql=INSERT_USGAE_RECORDS;
    PreparedStatement pstmt=null;
    pstmt=txn.prepareAutoCloseStatement(sql);
    for (    UsageVO usageRecord : usageRecords) {
      pstmt.setLong(1,usageRecord.getZoneId());
      pstmt.setLong(2,usageRecord.getAccountId());
      pstmt.setLong(3,usageRecord.getDomainId());
      pstmt.setString(4,usageRecord.getDescription());
      pstmt.setString(5,usageRecord.getUsageDisplay());
      pstmt.setInt(6,usageRecord.getUsageType());
      pstmt.setDouble(7,usageRecord.getRawUsage());
      if (usageRecord.getVmInstanceId() != null) {
        pstmt.setLong(8,usageRecord.getVmInstanceId());
      }
 else {
        pstmt.setNull(8,Types.BIGINT);
      }
      pstmt.setString(9,usageRecord.getVmName());
      if (usageRecord.getOfferingId() != null) {
        pstmt.setLong(10,usageRecord.getOfferingId());
      }
 else {
        pstmt.setNull(10,Types.BIGINT);
      }
      if (usageRecord.getTemplateId() != null) {
        pstmt.setLong(11,usageRecord.getTemplateId());
      }
 else {
        pstmt.setNull(11,Types.BIGINT);
      }
      if (usageRecord.getUsageId() != null) {
        pstmt.setLong(12,usageRecord.getUsageId());
      }
 else {
        pstmt.setNull(12,Types.BIGINT);
      }
      pstmt.setString(13,usageRecord.getType());
      if (usageRecord.getSize() != null) {
        pstmt.setLong(14,usageRecord.getSize());
      }
 else {
        pstmt.setNull(14,Types.BIGINT);
      }
      if (usageRecord.getNetworkId() != null) {
        pstmt.setLong(15,usageRecord.getNetworkId());
      }
 else {
        pstmt.setNull(15,Types.BIGINT);
      }
      pstmt.setTimestamp(16,new Timestamp(usageRecord.getStartDate().getTime()));
      pstmt.setTimestamp(17,new Timestamp(usageRecord.getEndDate().getTime()));
      if (usageRecord.getVirtualSize() != null) {
        pstmt.setLong(18,usageRecord.getSize());
      }
 else {
        pstmt.setNull(18,Types.BIGINT);
      }
      pstmt.addBatch();
    }
    pstmt.executeBatch();
    txn.commit();
  }
 catch (  Exception ex) {
    txn.rollback();
    s_logger.error("String_Node_Str",ex);
    throw new CloudRuntimeException(ex.getMessage());
  }
}

Fixed version (ground truth):
@Override public void saveUsageRecords(List<UsageVO> usageRecords){
  TransactionLegacy txn=TransactionLegacy.currentTxn();
  try {
    txn.start();
    String sql=INSERT_USGAE_RECORDS;
    PreparedStatement pstmt=null;
    pstmt=txn.prepareAutoCloseStatement(sql);
    for (    UsageVO usageRecord : usageRecords) {
      pstmt.setLong(1,usageRecord.getZoneId());
      pstmt.setLong(2,usageRecord.getAccountId());
      pstmt.setLong(3,usageRecord.getDomainId());
      pstmt.setString(4,usageRecord.getDescription());
      pstmt.setString(5,usageRecord.getUsageDisplay());
      pstmt.setInt(6,usageRecord.getUsageType());
      pstmt.setDouble(7,usageRecord.getRawUsage());
      if (usageRecord.getVmInstanceId() != null) {
        pstmt.setLong(8,usageRecord.getVmInstanceId());
      }
 else {
        pstmt.setNull(8,Types.BIGINT);
      }
      pstmt.setString(9,usageRecord.getVmName());
      if (usageRecord.getOfferingId() != null) {
        pstmt.setLong(10,usageRecord.getOfferingId());
      }
 else {
        pstmt.setNull(10,Types.BIGINT);
      }
      if (usageRecord.getTemplateId() != null) {
        pstmt.setLong(11,usageRecord.getTemplateId());
      }
 else {
        pstmt.setNull(11,Types.BIGINT);
      }
      if (usageRecord.getUsageId() != null) {
        pstmt.setLong(12,usageRecord.getUsageId());
      }
 else {
        pstmt.setNull(12,Types.BIGINT);
      }
      pstmt.setString(13,usageRecord.getType());
      if (usageRecord.getSize() != null) {
        pstmt.setLong(14,usageRecord.getSize());
      }
 else {
        pstmt.setNull(14,Types.BIGINT);
      }
      if (usageRecord.getNetworkId() != null) {
        pstmt.setLong(15,usageRecord.getNetworkId());
      }
 else {
        pstmt.setNull(15,Types.BIGINT);
      }
      pstmt.setString(16,DateUtil.getDateDisplayString(s_gmtTimeZone,usageRecord.getStartDate()));
      pstmt.setString(17,DateUtil.getDateDisplayString(s_gmtTimeZone,usageRecord.getEndDate()));
      if (usageRecord.getVirtualSize() != null) {
        pstmt.setLong(18,usageRecord.getSize());
      }
 else {
        pstmt.setNull(18,Types.BIGINT);
      }
      pstmt.addBatch();
    }
    pstmt.executeBatch();
    txn.commit();
  }
 catch (  Exception ex) {
    txn.rollback();
    s_logger.error("String_Node_Str",ex);
    throw new CloudRuntimeException(ex.getMessage());
  }
}