Program: 105703
Project: 105703
Buggy source:
private UserVmVO commitUserVm(final DataCenter zone,final VirtualMachineTemplate template,final String hostName,final String displayName,final Account owner,final Long diskOfferingId,final Long diskSize,final String userData,final HypervisorType hypervisor,final Account caller,final Boolean isDisplayVm,final String keyboard,final long accountId,final ServiceOfferingVO offering,final boolean isIso,final String sshPublicKey,final LinkedHashMap<String,NicProfile> networkNicMap,final long id,final String instanceName,final String uuidName,final HypervisorType hypervisorType,final Map<String,String> customParameters) throws InsufficientCapacityException {
  return Transaction.execute(new TransactionCallbackWithException<UserVmVO,InsufficientCapacityException>(){
    @Override public UserVmVO doInTransaction(    TransactionStatus status) throws InsufficientCapacityException {
      UserVmVO vm=new UserVmVO(id,instanceName,displayName,template.getId(),hypervisorType,template.getGuestOSId(),offering.getOfferHA(),offering.getLimitCpuUse(),owner.getDomainId(),owner.getId(),offering.getId(),userData,hostName,diskOfferingId);
      vm.setUuid(uuidName);
      vm.setDynamicallyScalable(template.isDynamicallyScalable());
      Map<String,String> details=template.getDetails();
      if (details != null && !details.isEmpty()) {
        vm.details.putAll(details);
      }
      if (sshPublicKey != null) {
        vm.setDetail("String_Node_Str",sshPublicKey);
      }
      if (keyboard != null && !keyboard.isEmpty())       vm.setDetail(VmDetailConstants.KEYBOARD,keyboard);
      if (isIso) {
        vm.setIsoId(template.getId());
      }
      Long rootDiskSize=null;
      if (customParameters.containsKey("String_Node_Str")) {
        if (NumbersUtil.parseLong(customParameters.get("String_Node_Str"),-1) <= 0) {
          throw new InvalidParameterValueException("String_Node_Str");
        }
        rootDiskSize=Long.parseLong(customParameters.get("String_Node_Str"));
        if (hypervisor != HypervisorType.KVM) {
          throw new InvalidParameterValueException("String_Node_Str" + hypervisor + "String_Node_Str");
        }
        VMTemplateVO templateVO=_templateDao.findById(template.getId());
        if (templateVO == null) {
          throw new InvalidParameterValueException("String_Node_Str" + template.getId());
        }
        if ((rootDiskSize << 30) < templateVO.getSize()) {
          throw new InvalidParameterValueException("String_Node_Str" + templateVO.getSize());
        }
 else {
          s_logger.debug("String_Node_Str" + (rootDiskSize << 30) + "String_Node_Str"+ templateVO.getSize());
        }
        s_logger.debug("String_Node_Str" + rootDiskSize);
        customParameters.remove("String_Node_Str");
      }
      if (isDisplayVm != null) {
        vm.setDisplayVm(isDisplayVm);
      }
 else {
        vm.setDisplayVm(true);
      }
      if (hypervisorType.equals(HypervisorType.VMware)) {
        UserVmCloneType cloneType=UserVmCloneType.linked;
        String value=_configDao.getValue(Config.VmwareCreateFullClone.key());
        if (value != null) {
          if (Boolean.parseBoolean(value) == true)           cloneType=UserVmCloneType.full;
        }
        UserVmCloneSettingVO vmCloneSettingVO=new UserVmCloneSettingVO(id,cloneType.toString());
        _vmCloneSettingDao.persist(vmCloneSettingVO);
      }
      long guestOSId=template.getGuestOSId();
      GuestOSVO guestOS=_guestOSDao.findById(guestOSId);
      long guestOSCategoryId=guestOS.getCategoryId();
      GuestOSCategoryVO guestOSCategory=_guestOSCategoryDao.findById(guestOSCategoryId);
      if (hypervisorType.equals(HypervisorType.VMware)) {
        if (guestOS.getDisplayName().toLowerCase().contains("String_Node_Str")) {
          vm.setDetail("String_Node_Str","String_Node_Str");
          vm.setDetail(VmDetailConstants.ROOK_DISK_CONTROLLER,"String_Node_Str");
          vm.setDetail("String_Node_Str","String_Node_Str");
          s_logger.info("String_Node_Str");
        }
      }
      _vmDao.persist(vm);
      if (customParameters != null && customParameters.size() > 0) {
        for (        String key : customParameters.keySet()) {
          vm.setDetail(key,customParameters.get(key));
        }
      }
      _vmDao.saveDetails(vm);
      s_logger.debug("String_Node_Str");
      DataCenterDeployment plan=new DataCenterDeployment(zone.getId());
      List<String> computeTags=new ArrayList<String>();
      computeTags.add(offering.getHostTag());
      List<String> rootDiskTags=new ArrayList<String>();
      rootDiskTags.add(offering.getTags());
      if (isIso) {
        _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(),Long.toString(owner.getAccountId()),vm.getIsoId().toString(),hostName,displayName,hypervisor.name(),guestOSCategory.getName(),offering.getCpu(),offering.getSpeed(),offering.getRamSize(),diskSize,computeTags,rootDiskTags,networkNicMap,plan);
      }
 else {
        _orchSrvc.createVirtualMachine(vm.getUuid(),Long.toString(owner.getAccountId()),Long.toString(template.getId()),hostName,displayName,hypervisor.name(),offering.getCpu(),offering.getSpeed(),offering.getRamSize(),diskSize,computeTags,rootDiskTags,networkNicMap,plan,rootDiskSize);
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + vm);
      }
      CallContext.current().setEventDetails("String_Node_Str" + vm.getId());
      if (!offering.isDynamic()) {
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE,accountId,zone.getId(),vm.getId(),vm.getHostName(),offering.getId(),template.getId(),hypervisorType.toString(),VirtualMachine.class.getName(),vm.getUuid(),vm.isDisplayVm());
      }
 else {
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE,accountId,zone.getId(),vm.getId(),vm.getHostName(),offering.getId(),template.getId(),hypervisorType.toString(),VirtualMachine.class.getName(),vm.getUuid(),customParameters,vm.isDisplayVm());
      }
      resourceCountIncrement(accountId,isDisplayVm,new Long(offering.getCpu()),new Long(offering.getRamSize()));
      return vm;
    }
  }
);
}

Fixed version (ground truth):
private UserVmVO commitUserVm(final DataCenter zone,final VirtualMachineTemplate template,final String hostName,final String displayName,final Account owner,final Long diskOfferingId,final Long diskSize,final String userData,final HypervisorType hypervisor,final Account caller,final Boolean isDisplayVm,final String keyboard,final long accountId,final ServiceOfferingVO offering,final boolean isIso,final String sshPublicKey,final LinkedHashMap<String,NicProfile> networkNicMap,final long id,final String instanceName,final String uuidName,final HypervisorType hypervisorType,final Map<String,String> customParameters) throws InsufficientCapacityException {
  return Transaction.execute(new TransactionCallbackWithException<UserVmVO,InsufficientCapacityException>(){
    @Override public UserVmVO doInTransaction(    TransactionStatus status) throws InsufficientCapacityException {
      UserVmVO vm=new UserVmVO(id,instanceName,displayName,template.getId(),hypervisorType,template.getGuestOSId(),offering.getOfferHA(),offering.getLimitCpuUse(),owner.getDomainId(),owner.getId(),offering.getId(),userData,hostName,diskOfferingId);
      vm.setUuid(uuidName);
      vm.setDynamicallyScalable(template.isDynamicallyScalable());
      Map<String,String> details=template.getDetails();
      if (details != null && !details.isEmpty()) {
        vm.details.putAll(details);
      }
      if (sshPublicKey != null) {
        vm.setDetail("String_Node_Str",sshPublicKey);
      }
      if (keyboard != null && !keyboard.isEmpty())       vm.setDetail(VmDetailConstants.KEYBOARD,keyboard);
      if (isIso) {
        vm.setIsoId(template.getId());
      }
      Long rootDiskSize=null;
      if (customParameters.containsKey("String_Node_Str")) {
        if (NumbersUtil.parseLong(customParameters.get("String_Node_Str"),-1) <= 0) {
          throw new InvalidParameterValueException("String_Node_Str");
        }
        rootDiskSize=Long.parseLong(customParameters.get("String_Node_Str"));
        if (hypervisor != HypervisorType.KVM) {
          throw new InvalidParameterValueException("String_Node_Str" + hypervisor + "String_Node_Str");
        }
        VMTemplateVO templateVO=_templateDao.findById(template.getId());
        if (templateVO == null) {
          throw new InvalidParameterValueException("String_Node_Str" + template.getId());
        }
        if ((rootDiskSize << 30) < templateVO.getSize()) {
          throw new InvalidParameterValueException("String_Node_Str" + templateVO.getSize());
        }
 else {
          s_logger.debug("String_Node_Str" + (rootDiskSize << 30) + "String_Node_Str"+ templateVO.getSize());
        }
        s_logger.debug("String_Node_Str" + rootDiskSize);
        customParameters.remove("String_Node_Str");
      }
      if (isDisplayVm != null) {
        vm.setDisplayVm(isDisplayVm);
      }
 else {
        vm.setDisplayVm(true);
      }
      if (hypervisorType.equals(HypervisorType.VMware)) {
        UserVmCloneType cloneType=UserVmCloneType.linked;
        String value=_configDao.getValue(Config.VmwareCreateFullClone.key());
        if (value != null) {
          if (Boolean.parseBoolean(value) == true)           cloneType=UserVmCloneType.full;
        }
        UserVmCloneSettingVO vmCloneSettingVO=new UserVmCloneSettingVO(id,cloneType.toString());
        _vmCloneSettingDao.persist(vmCloneSettingVO);
      }
      long guestOSId=template.getGuestOSId();
      GuestOSVO guestOS=_guestOSDao.findById(guestOSId);
      long guestOSCategoryId=guestOS.getCategoryId();
      GuestOSCategoryVO guestOSCategory=_guestOSCategoryDao.findById(guestOSCategoryId);
      if (hypervisorType.equals(HypervisorType.VMware)) {
        if (guestOS.getDisplayName().toLowerCase().contains("String_Node_Str")) {
          vm.setDetail("String_Node_Str","String_Node_Str");
          vm.setDetail(VmDetailConstants.ROOK_DISK_CONTROLLER,"String_Node_Str");
          vm.setDetail("String_Node_Str","String_Node_Str");
          s_logger.info("String_Node_Str");
        }
      }
      _vmDao.persist(vm);
      for (      String key : customParameters.keySet()) {
        vm.setDetail(key,customParameters.get(key));
      }
      _vmDao.saveDetails(vm);
      s_logger.debug("String_Node_Str");
      DataCenterDeployment plan=new DataCenterDeployment(zone.getId());
      List<String> computeTags=new ArrayList<String>();
      computeTags.add(offering.getHostTag());
      List<String> rootDiskTags=new ArrayList<String>();
      rootDiskTags.add(offering.getTags());
      if (isIso) {
        _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(),Long.toString(owner.getAccountId()),vm.getIsoId().toString(),hostName,displayName,hypervisor.name(),guestOSCategory.getName(),offering.getCpu(),offering.getSpeed(),offering.getRamSize(),diskSize,computeTags,rootDiskTags,networkNicMap,plan);
      }
 else {
        _orchSrvc.createVirtualMachine(vm.getUuid(),Long.toString(owner.getAccountId()),Long.toString(template.getId()),hostName,displayName,hypervisor.name(),offering.getCpu(),offering.getSpeed(),offering.getRamSize(),diskSize,computeTags,rootDiskTags,networkNicMap,plan,rootDiskSize);
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + vm);
      }
      CallContext.current().setEventDetails("String_Node_Str" + vm.getId());
      if (!offering.isDynamic()) {
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE,accountId,zone.getId(),vm.getId(),vm.getHostName(),offering.getId(),template.getId(),hypervisorType.toString(),VirtualMachine.class.getName(),vm.getUuid(),vm.isDisplayVm());
      }
 else {
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE,accountId,zone.getId(),vm.getId(),vm.getHostName(),offering.getId(),template.getId(),hypervisorType.toString(),VirtualMachine.class.getName(),vm.getUuid(),customParameters,vm.isDisplayVm());
      }
      resourceCountIncrement(accountId,isDisplayVm,new Long(offering.getCpu()),new Long(offering.getRamSize()));
      return vm;
    }
  }
);
}