Program: 89909
Project: 89909
Buggy source:
@Override public UserVmResponse createUserVmResponse(UserVm userVm){
  UserVmResponse userVmResponse=new UserVmResponse();
  Account acct=ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
  if ((acct != null) && (acct.getRemoved() == null)) {
    userVmResponse.setAccountName(acct.getAccountName());
    userVmResponse.setDomainId(acct.getDomainId());
    userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
  }
 else {
    return null;
  }
  userVmResponse.setId(userVm.getId());
  userVmResponse.setName(userVm.getHostName());
  userVmResponse.setCreated(userVm.getCreated());
  if (userVm.getState() != null) {
    userVmResponse.setState(userVm.getState().toString());
  }
  userVmResponse.setHaEnable(userVm.isHaEnabled());
  if (userVm.getDisplayName() != null) {
    userVmResponse.setDisplayName(userVm.getDisplayName());
  }
 else {
    userVmResponse.setDisplayName(userVm.getHostName());
  }
  InstanceGroupVO group=ApiDBUtils.findInstanceGroupForVM(userVm.getId());
  if (group != null) {
    userVmResponse.setGroup(group.getName());
    userVmResponse.setGroupId(group.getId());
  }
  userVmResponse.setZoneId(userVm.getDataCenterId());
  userVmResponse.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
  Account account=UserContext.current().getAccount();
  if (((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) {
    userVmResponse.setHostId(userVm.getHostId());
    userVmResponse.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName());
  }
  VMTemplateVO template=ApiDBUtils.findTemplateById(userVm.getTemplateId());
  if (template != null) {
    userVmResponse.setTemplateId(userVm.getTemplateId());
    userVmResponse.setTemplateName(template.getName());
    userVmResponse.setTemplateDisplayText(template.getDisplayText());
    userVmResponse.setPasswordEnabled(template.getEnablePassword());
  }
 else {
    userVmResponse.setTemplateId(-1L);
    userVmResponse.setTemplateName("String_Node_Str");
    userVmResponse.setTemplateDisplayText("String_Node_Str");
    userVmResponse.setPasswordEnabled(false);
  }
  if (userVm.getPassword() != null) {
    userVmResponse.setPassword(userVm.getPassword());
  }
  if (userVm.getIsoId() != null) {
    VMTemplateVO iso=ApiDBUtils.findTemplateById(userVm.getIsoId());
    if (iso != null) {
      userVmResponse.setIsoId(userVm.getIsoId());
      userVmResponse.setIsoName(iso.getName());
    }
  }
  ServiceOffering offering=ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
  userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId());
  userVmResponse.setServiceOfferingName(offering.getName());
  userVmResponse.setCpuNumber(offering.getCpu());
  userVmResponse.setCpuSpeed(offering.getSpeed());
  userVmResponse.setMemory(offering.getRamSize());
  VolumeVO rootVolume=ApiDBUtils.findRootVolume(userVm.getId());
  if (rootVolume != null) {
    userVmResponse.setRootDeviceId(rootVolume.getDeviceId());
    String rootDeviceType="String_Node_Str";
    if (rootVolume.getPoolId() != null) {
      StoragePoolVO storagePool=ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
      rootDeviceType=storagePool.getPoolType().toString();
    }
    userVmResponse.setRootDeviceType(rootDeviceType);
  }
  DecimalFormat decimalFormat=new DecimalFormat("String_Node_Str");
  String cpuUsed=null;
  VmStats vmStats=ApiDBUtils.getVmStatistics(userVm.getId());
  if (vmStats != null) {
    float cpuUtil=(float)vmStats.getCPUUtilization();
    cpuUsed=decimalFormat.format(cpuUtil) + "String_Node_Str";
    userVmResponse.setCpuUsed(cpuUsed);
    Long networkKbRead=Double.doubleToLongBits(vmStats.getNetworkReadKBs());
    userVmResponse.setNetworkKbsRead(networkKbRead);
    Long networkKbWrite=Double.doubleToLongBits(vmStats.getNetworkWriteKBs());
    userVmResponse.setNetworkKbsWrite(networkKbWrite);
  }
  userVmResponse.setGuestOsId(userVm.getGuestOSId());
  userVmResponse.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(userVm.getId()));
  List<? extends Nic> nics=ApiDBUtils.getNics(userVm);
  List<NicResponse> nicResponses=new ArrayList<NicResponse>();
  for (  Nic singleNic : nics) {
    NicResponse nicResponse=new NicResponse();
    nicResponse.setId(singleNic.getId());
    nicResponse.setIpaddress(singleNic.getIp4Address());
    nicResponse.setGateway(singleNic.getGateway());
    nicResponse.setNetmask(singleNic.getNetmask());
    nicResponse.setNetworkid(singleNic.getNetworkId());
    if (acct.getType() == Account.ACCOUNT_TYPE_ADMIN) {
      if (singleNic.getBroadcastUri() != null) {
        nicResponse.setBroadcastUri(singleNic.getBroadcastUri().toString());
      }
      if (singleNic.getIsolationUri() != null) {
        nicResponse.setIsolationUri(singleNic.getIsolationUri().toString());
      }
    }
    Network network=ApiDBUtils.findNetworkById(singleNic.getNetworkId());
    nicResponse.setTrafficType(network.getTrafficType().toString());
    NetworkOffering networkOffering=ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
    if (networkOffering.getGuestIpType() != null) {
      nicResponse.setType(networkOffering.getGuestIpType().toString());
    }
    nicResponse.setObjectName("String_Node_Str");
    nicResponses.add(nicResponse);
  }
  userVmResponse.setNics(nicResponses);
  userVmResponse.setObjectName("String_Node_Str");
  return userVmResponse;
}

Fixed version (ground truth):
@Override public UserVmResponse createUserVmResponse(UserVm userVm){
  UserVmResponse userVmResponse=new UserVmResponse();
  Account acct=ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
  if ((acct != null) && (acct.getRemoved() == null)) {
    userVmResponse.setAccountName(acct.getAccountName());
    userVmResponse.setDomainId(acct.getDomainId());
    userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
  }
 else {
    return null;
  }
  userVmResponse.setId(userVm.getId());
  userVmResponse.setName(userVm.getName());
  userVmResponse.setCreated(userVm.getCreated());
  if (userVm.getState() != null) {
    userVmResponse.setState(userVm.getState().toString());
  }
  userVmResponse.setHaEnable(userVm.isHaEnabled());
  if (userVm.getDisplayName() != null) {
    userVmResponse.setDisplayName(userVm.getDisplayName());
  }
 else {
    userVmResponse.setDisplayName(userVm.getName());
  }
  InstanceGroupVO group=ApiDBUtils.findInstanceGroupForVM(userVm.getId());
  if (group != null) {
    userVmResponse.setGroup(group.getName());
    userVmResponse.setGroupId(group.getId());
  }
  userVmResponse.setZoneId(userVm.getDataCenterId());
  userVmResponse.setZoneName(ApiDBUtils.findZoneById(userVm.getDataCenterId()).getName());
  Account account=UserContext.current().getAccount();
  if (((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) {
    userVmResponse.setHostId(userVm.getHostId());
    userVmResponse.setHostName(ApiDBUtils.findHostById(userVm.getHostId()).getName());
  }
  VMTemplateVO template=ApiDBUtils.findTemplateById(userVm.getTemplateId());
  if (template != null) {
    userVmResponse.setTemplateId(userVm.getTemplateId());
    userVmResponse.setTemplateName(template.getName());
    userVmResponse.setTemplateDisplayText(template.getDisplayText());
    userVmResponse.setPasswordEnabled(template.getEnablePassword());
  }
 else {
    userVmResponse.setTemplateId(-1L);
    userVmResponse.setTemplateName("String_Node_Str");
    userVmResponse.setTemplateDisplayText("String_Node_Str");
    userVmResponse.setPasswordEnabled(false);
  }
  if (userVm.getPassword() != null) {
    userVmResponse.setPassword(userVm.getPassword());
  }
  if (userVm.getIsoId() != null) {
    VMTemplateVO iso=ApiDBUtils.findTemplateById(userVm.getIsoId());
    if (iso != null) {
      userVmResponse.setIsoId(userVm.getIsoId());
      userVmResponse.setIsoName(iso.getName());
    }
  }
  ServiceOffering offering=ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
  userVmResponse.setServiceOfferingId(userVm.getServiceOfferingId());
  userVmResponse.setServiceOfferingName(offering.getName());
  userVmResponse.setCpuNumber(offering.getCpu());
  userVmResponse.setCpuSpeed(offering.getSpeed());
  userVmResponse.setMemory(offering.getRamSize());
  VolumeVO rootVolume=ApiDBUtils.findRootVolume(userVm.getId());
  if (rootVolume != null) {
    userVmResponse.setRootDeviceId(rootVolume.getDeviceId());
    String rootDeviceType="String_Node_Str";
    if (rootVolume.getPoolId() != null) {
      StoragePoolVO storagePool=ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
      rootDeviceType=storagePool.getPoolType().toString();
    }
    userVmResponse.setRootDeviceType(rootDeviceType);
  }
  DecimalFormat decimalFormat=new DecimalFormat("String_Node_Str");
  String cpuUsed=null;
  VmStats vmStats=ApiDBUtils.getVmStatistics(userVm.getId());
  if (vmStats != null) {
    float cpuUtil=(float)vmStats.getCPUUtilization();
    cpuUsed=decimalFormat.format(cpuUtil) + "String_Node_Str";
    userVmResponse.setCpuUsed(cpuUsed);
    Long networkKbRead=Double.doubleToLongBits(vmStats.getNetworkReadKBs());
    userVmResponse.setNetworkKbsRead(networkKbRead);
    Long networkKbWrite=Double.doubleToLongBits(vmStats.getNetworkWriteKBs());
    userVmResponse.setNetworkKbsWrite(networkKbWrite);
  }
  userVmResponse.setGuestOsId(userVm.getGuestOSId());
  userVmResponse.setNetworkGroupList(ApiDBUtils.getNetworkGroupsNamesForVm(userVm.getId()));
  List<? extends Nic> nics=ApiDBUtils.getNics(userVm);
  List<NicResponse> nicResponses=new ArrayList<NicResponse>();
  for (  Nic singleNic : nics) {
    NicResponse nicResponse=new NicResponse();
    nicResponse.setId(singleNic.getId());
    nicResponse.setIpaddress(singleNic.getIp4Address());
    nicResponse.setGateway(singleNic.getGateway());
    nicResponse.setNetmask(singleNic.getNetmask());
    nicResponse.setNetworkid(singleNic.getNetworkId());
    if (acct.getType() == Account.ACCOUNT_TYPE_ADMIN) {
      if (singleNic.getBroadcastUri() != null) {
        nicResponse.setBroadcastUri(singleNic.getBroadcastUri().toString());
      }
      if (singleNic.getIsolationUri() != null) {
        nicResponse.setIsolationUri(singleNic.getIsolationUri().toString());
      }
    }
    Network network=ApiDBUtils.findNetworkById(singleNic.getNetworkId());
    nicResponse.setTrafficType(network.getTrafficType().toString());
    NetworkOffering networkOffering=ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
    if (networkOffering.getGuestIpType() != null) {
      nicResponse.setType(networkOffering.getGuestIpType().toString());
    }
    nicResponse.setObjectName("String_Node_Str");
    nicResponses.add(nicResponse);
  }
  userVmResponse.setNics(nicResponses);
  userVmResponse.setObjectName("String_Node_Str");
  return userVmResponse;
}