Program: 105663
Project: 105663
Buggy source:
@Override public UsageRecordResponse createUsageResponse(Usage usageRecord){
  UsageRecordResponse usageRecResponse=new UsageRecordResponse();
  Account account=ApiDBUtils.findAccountById(usageRecord.getAccountId());
  if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    Project project=ApiDBUtils.findProjectByProjectAccountId(account.getId());
    usageRecResponse.setProjectId(project.getUuid());
    usageRecResponse.setProjectName(project.getName());
  }
 else {
    usageRecResponse.setAccountId(account.getUuid());
    usageRecResponse.setAccountName(account.getAccountName());
  }
  Domain domain=ApiDBUtils.findDomainById(usageRecord.getDomainId());
  if (domain != null) {
    usageRecResponse.setDomainId(domain.getUuid());
  }
  if (usageRecord.getZoneId() != null) {
    DataCenter zone=ApiDBUtils.findZoneById(usageRecord.getZoneId());
    if (zone != null) {
      usageRecResponse.setZoneId(zone.getUuid());
    }
  }
  usageRecResponse.setDescription(usageRecord.getDescription());
  usageRecResponse.setUsage(usageRecord.getUsageDisplay());
  usageRecResponse.setUsageType(usageRecord.getUsageType());
  if (usageRecord.getVmInstanceId() != null) {
    VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getVmInstanceId());
    if (vm != null) {
      usageRecResponse.setVirtualMachineId(vm.getUuid());
    }
  }
  usageRecResponse.setVmName(usageRecord.getVmName());
  if (usageRecord.getTemplateId() != null) {
    VMTemplateVO template=ApiDBUtils.findTemplateById(usageRecord.getTemplateId());
    if (template != null) {
      usageRecResponse.setTemplateId(template.getUuid());
    }
  }
  if (usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM) {
    ServiceOfferingVO svcOffering=_entityMgr.findByIdIncludingRemoved(ServiceOfferingVO.class,usageRecord.getOfferingId().toString());
    usageRecResponse.setOfferingId(svcOffering.getUuid());
    VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getUsageId().toString());
    if (vm != null) {
      usageRecResponse.setUsageId(vm.getUuid());
    }
    usageRecResponse.setType(usageRecord.getType());
    usageRecResponse.setCpuNumber(usageRecord.getCpuCores());
    usageRecResponse.setCpuSpeed(usageRecord.getCpuSpeed());
    usageRecResponse.setMemory(usageRecord.getMemory());
  }
 else   if (usageRecord.getUsageType() == UsageTypes.IP_ADDRESS) {
    usageRecResponse.setSourceNat((usageRecord.getType().equals("String_Node_Str")) ? true : false);
    usageRecResponse.setSystem((usageRecord.getSize() == 1) ? true : false);
    IPAddressVO ip=_entityMgr.findByIdIncludingRemoved(IPAddressVO.class,usageRecord.getUsageId().toString());
    if (ip != null) {
      usageRecResponse.setUsageId(ip.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_SENT || usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_RECEIVED) {
    usageRecResponse.setType(usageRecord.getType());
    if (usageRecord.getType().equals("String_Node_Str")) {
      VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getUsageId().toString());
      if (vm != null) {
        usageRecResponse.setUsageId(vm.getUuid());
      }
    }
 else {
      HostVO host=_entityMgr.findByIdIncludingRemoved(HostVO.class,usageRecord.getUsageId().toString());
      if (host != null) {
        usageRecResponse.setUsageId(host.getUuid());
      }
    }
    NetworkVO network=_entityMgr.findByIdIncludingRemoved(NetworkVO.class,usageRecord.getNetworkId().toString());
    if (network != null) {
      usageRecResponse.setNetworkId(network.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.VM_DISK_IO_READ || usageRecord.getUsageType() == UsageTypes.VM_DISK_IO_WRITE || usageRecord.getUsageType() == UsageTypes.VM_DISK_BYTES_READ || usageRecord.getUsageType() == UsageTypes.VM_DISK_BYTES_WRITE) {
    usageRecResponse.setType(usageRecord.getType());
    VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getVmInstanceId().toString());
    if (vm != null) {
      usageRecResponse.setVirtualMachineId(vm.getUuid());
    }
    VolumeVO volume=_entityMgr.findByIdIncludingRemoved(VolumeVO.class,usageRecord.getUsageId().toString());
    if (volume != null) {
      usageRecResponse.setUsageId(volume.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.VOLUME) {
    VolumeVO volume=_entityMgr.findByIdIncludingRemoved(VolumeVO.class,usageRecord.getUsageId().toString());
    if (volume != null) {
      usageRecResponse.setUsageId(volume.getUuid());
    }
    usageRecResponse.setSize(usageRecord.getSize());
    if (usageRecord.getOfferingId() != null) {
      DiskOfferingVO diskOff=_entityMgr.findByIdIncludingRemoved(DiskOfferingVO.class,usageRecord.getOfferingId().toString());
      usageRecResponse.setOfferingId(diskOff.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO) {
    VMTemplateVO tmpl=_entityMgr.findByIdIncludingRemoved(VMTemplateVO.class,usageRecord.getUsageId().toString());
    usageRecResponse.setUsageId(tmpl.getUuid());
    if (tmpl != null) {
      usageRecResponse.setUsageId(tmpl.getUuid());
    }
    usageRecResponse.setSize(usageRecord.getSize());
    if (usageRecord.getUsageType() == UsageTypes.ISO) {
      usageRecResponse.setVirtualSize(usageRecord.getSize());
    }
 else {
      usageRecResponse.setVirtualSize(usageRecord.getVirtualSize());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.SNAPSHOT) {
    SnapshotVO snap=_entityMgr.findByIdIncludingRemoved(SnapshotVO.class,usageRecord.getUsageId().toString());
    if (snap != null) {
      usageRecResponse.setUsageId(snap.getUuid());
    }
    usageRecResponse.setSize(usageRecord.getSize());
  }
 else   if (usageRecord.getUsageType() == UsageTypes.LOAD_BALANCER_POLICY) {
    LoadBalancerVO lb=_entityMgr.findByIdIncludingRemoved(LoadBalancerVO.class,usageRecord.getUsageId().toString());
    if (lb != null) {
      usageRecResponse.setUsageId(lb.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.PORT_FORWARDING_RULE) {
    PortForwardingRuleVO pf=_entityMgr.findByIdIncludingRemoved(PortForwardingRuleVO.class,usageRecord.getUsageId().toString());
    if (pf != null) {
      usageRecResponse.setUsageId(pf.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.NETWORK_OFFERING) {
    NetworkOfferingVO netOff=_entityMgr.findByIdIncludingRemoved(NetworkOfferingVO.class,usageRecord.getOfferingId().toString());
    usageRecResponse.setOfferingId(netOff.getUuid());
    usageRecResponse.setDefault((usageRecord.getUsageId() == 1) ? true : false);
  }
 else   if (usageRecord.getUsageType() == UsageTypes.VPN_USERS) {
    VpnUserVO vpnUser=_entityMgr.findByIdIncludingRemoved(VpnUserVO.class,usageRecord.getUsageId().toString());
    if (vpnUser != null) {
      usageRecResponse.setUsageId(vpnUser.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.SECURITY_GROUP) {
    SecurityGroupVO sg=_entityMgr.findByIdIncludingRemoved(SecurityGroupVO.class,usageRecord.getUsageId().toString());
    if (sg != null) {
      usageRecResponse.setUsageId(sg.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.VM_SNAPSHOT) {
    VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getVmInstanceId().toString());
    if (vm != null) {
      usageRecResponse.setVmName(vm.getInstanceName());
      usageRecResponse.setUsageId(vm.getUuid());
    }
    usageRecResponse.setSize(usageRecord.getSize());
    if (usageRecord.getOfferingId() != null) {
      usageRecResponse.setOfferingId(usageRecord.getOfferingId().toString());
    }
  }
  if (usageRecord.getRawUsage() != null) {
    DecimalFormat decimalFormat=new DecimalFormat("String_Node_Str");
    usageRecResponse.setRawUsage(decimalFormat.format(usageRecord.getRawUsage()));
  }
  if (usageRecord.getStartDate() != null) {
    usageRecResponse.setStartDate(getDateStringInternal(usageRecord.getStartDate()));
  }
  if (usageRecord.getEndDate() != null) {
    usageRecResponse.setEndDate(getDateStringInternal(usageRecord.getEndDate()));
  }
  return usageRecResponse;
}

Fixed version (ground truth):
@Override public UsageRecordResponse createUsageResponse(Usage usageRecord){
  UsageRecordResponse usageRecResponse=new UsageRecordResponse();
  Account account=ApiDBUtils.findAccountById(usageRecord.getAccountId());
  if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    Project project=ApiDBUtils.findProjectByProjectAccountId(account.getId());
    usageRecResponse.setProjectId(project.getUuid());
    usageRecResponse.setProjectName(project.getName());
  }
 else {
    usageRecResponse.setAccountId(account.getUuid());
    usageRecResponse.setAccountName(account.getAccountName());
  }
  Domain domain=ApiDBUtils.findDomainById(usageRecord.getDomainId());
  if (domain != null) {
    usageRecResponse.setDomainId(domain.getUuid());
  }
  if (usageRecord.getZoneId() != null) {
    DataCenter zone=ApiDBUtils.findZoneById(usageRecord.getZoneId());
    if (zone != null) {
      usageRecResponse.setZoneId(zone.getUuid());
    }
  }
  usageRecResponse.setDescription(usageRecord.getDescription());
  usageRecResponse.setUsage(usageRecord.getUsageDisplay());
  usageRecResponse.setUsageType(usageRecord.getUsageType());
  if (usageRecord.getVmInstanceId() != null) {
    VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getVmInstanceId());
    if (vm != null) {
      usageRecResponse.setVirtualMachineId(vm.getUuid());
    }
  }
  usageRecResponse.setVmName(usageRecord.getVmName());
  if (usageRecord.getTemplateId() != null) {
    VMTemplateVO template=ApiDBUtils.findTemplateById(usageRecord.getTemplateId());
    if (template != null) {
      usageRecResponse.setTemplateId(template.getUuid());
    }
  }
  if (usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM) {
    ServiceOfferingVO svcOffering=_entityMgr.findByIdIncludingRemoved(ServiceOfferingVO.class,usageRecord.getOfferingId().toString());
    usageRecResponse.setOfferingId(svcOffering.getUuid());
    VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getUsageId().toString());
    if (vm != null) {
      usageRecResponse.setUsageId(vm.getUuid());
    }
    usageRecResponse.setType(usageRecord.getType());
    usageRecResponse.setCpuNumber(usageRecord.getCpuCores());
    usageRecResponse.setCpuSpeed(usageRecord.getCpuSpeed());
    usageRecResponse.setMemory(usageRecord.getMemory());
  }
 else   if (usageRecord.getUsageType() == UsageTypes.IP_ADDRESS) {
    usageRecResponse.setSourceNat((usageRecord.getType().equals("String_Node_Str")) ? true : false);
    usageRecResponse.setSystem((usageRecord.getSize() == 1) ? true : false);
    IPAddressVO ip=_entityMgr.findByIdIncludingRemoved(IPAddressVO.class,usageRecord.getUsageId().toString());
    if (ip != null) {
      usageRecResponse.setUsageId(ip.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_SENT || usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_RECEIVED) {
    usageRecResponse.setType(usageRecord.getType());
    if (usageRecord.getType().equals("String_Node_Str")) {
      VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getUsageId().toString());
      if (vm != null) {
        usageRecResponse.setUsageId(vm.getUuid());
      }
    }
 else {
      HostVO host=_entityMgr.findByIdIncludingRemoved(HostVO.class,usageRecord.getUsageId().toString());
      if (host != null) {
        usageRecResponse.setUsageId(host.getUuid());
      }
    }
    NetworkVO network=_entityMgr.findByIdIncludingRemoved(NetworkVO.class,usageRecord.getNetworkId().toString());
    if (network != null) {
      usageRecResponse.setNetworkId(network.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.VM_DISK_IO_READ || usageRecord.getUsageType() == UsageTypes.VM_DISK_IO_WRITE || usageRecord.getUsageType() == UsageTypes.VM_DISK_BYTES_READ || usageRecord.getUsageType() == UsageTypes.VM_DISK_BYTES_WRITE) {
    usageRecResponse.setType(usageRecord.getType());
    VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getVmInstanceId().toString());
    if (vm != null) {
      usageRecResponse.setVirtualMachineId(vm.getUuid());
    }
    VolumeVO volume=_entityMgr.findByIdIncludingRemoved(VolumeVO.class,usageRecord.getUsageId().toString());
    if (volume != null) {
      usageRecResponse.setUsageId(volume.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.VOLUME) {
    VolumeVO volume=_entityMgr.findByIdIncludingRemoved(VolumeVO.class,usageRecord.getUsageId().toString());
    if (volume != null) {
      usageRecResponse.setUsageId(volume.getUuid());
    }
    usageRecResponse.setSize(usageRecord.getSize());
    if (usageRecord.getOfferingId() != null) {
      DiskOfferingVO diskOff=_entityMgr.findByIdIncludingRemoved(DiskOfferingVO.class,usageRecord.getOfferingId().toString());
      usageRecResponse.setOfferingId(diskOff.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO) {
    VMTemplateVO tmpl=_entityMgr.findByIdIncludingRemoved(VMTemplateVO.class,usageRecord.getUsageId().toString());
    if (tmpl != null) {
      usageRecResponse.setUsageId(tmpl.getUuid());
    }
    usageRecResponse.setSize(usageRecord.getSize());
    if (usageRecord.getUsageType() == UsageTypes.ISO) {
      usageRecResponse.setVirtualSize(usageRecord.getSize());
    }
 else {
      usageRecResponse.setVirtualSize(usageRecord.getVirtualSize());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.SNAPSHOT) {
    SnapshotVO snap=_entityMgr.findByIdIncludingRemoved(SnapshotVO.class,usageRecord.getUsageId().toString());
    if (snap != null) {
      usageRecResponse.setUsageId(snap.getUuid());
    }
    usageRecResponse.setSize(usageRecord.getSize());
  }
 else   if (usageRecord.getUsageType() == UsageTypes.LOAD_BALANCER_POLICY) {
    LoadBalancerVO lb=_entityMgr.findByIdIncludingRemoved(LoadBalancerVO.class,usageRecord.getUsageId().toString());
    if (lb != null) {
      usageRecResponse.setUsageId(lb.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.PORT_FORWARDING_RULE) {
    PortForwardingRuleVO pf=_entityMgr.findByIdIncludingRemoved(PortForwardingRuleVO.class,usageRecord.getUsageId().toString());
    if (pf != null) {
      usageRecResponse.setUsageId(pf.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.NETWORK_OFFERING) {
    NetworkOfferingVO netOff=_entityMgr.findByIdIncludingRemoved(NetworkOfferingVO.class,usageRecord.getOfferingId().toString());
    usageRecResponse.setOfferingId(netOff.getUuid());
    usageRecResponse.setDefault((usageRecord.getUsageId() == 1) ? true : false);
  }
 else   if (usageRecord.getUsageType() == UsageTypes.VPN_USERS) {
    VpnUserVO vpnUser=_entityMgr.findByIdIncludingRemoved(VpnUserVO.class,usageRecord.getUsageId().toString());
    if (vpnUser != null) {
      usageRecResponse.setUsageId(vpnUser.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.SECURITY_GROUP) {
    SecurityGroupVO sg=_entityMgr.findByIdIncludingRemoved(SecurityGroupVO.class,usageRecord.getUsageId().toString());
    if (sg != null) {
      usageRecResponse.setUsageId(sg.getUuid());
    }
  }
 else   if (usageRecord.getUsageType() == UsageTypes.VM_SNAPSHOT) {
    VMInstanceVO vm=_entityMgr.findByIdIncludingRemoved(VMInstanceVO.class,usageRecord.getVmInstanceId().toString());
    if (vm != null) {
      usageRecResponse.setVmName(vm.getInstanceName());
      usageRecResponse.setUsageId(vm.getUuid());
    }
    usageRecResponse.setSize(usageRecord.getSize());
    if (usageRecord.getOfferingId() != null) {
      usageRecResponse.setOfferingId(usageRecord.getOfferingId().toString());
    }
  }
  if (usageRecord.getRawUsage() != null) {
    DecimalFormat decimalFormat=new DecimalFormat("String_Node_Str");
    usageRecResponse.setRawUsage(decimalFormat.format(usageRecord.getRawUsage()));
  }
  if (usageRecord.getStartDate() != null) {
    usageRecResponse.setStartDate(getDateStringInternal(usageRecord.getStartDate()));
  }
  if (usageRecord.getEndDate() != null) {
    usageRecResponse.setEndDate(getDateStringInternal(usageRecord.getEndDate()));
  }
  return usageRecResponse;
}