Program: 106180
Project: 106180
Buggy source:
@Override public VMInstanceVO reConfigureVm(String vmUuid,ServiceOffering oldServiceOffering,boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException {
  VMInstanceVO vm=_vmDao.findByUuid(vmUuid);
  long newServiceofferingId=vm.getServiceOfferingId();
  ServiceOffering newServiceOffering=_configMgr.getServiceOffering(newServiceofferingId);
  HostVO hostVo=_hostDao.findById(vm.getHostId());
  Float memoryOvercommitRatio=Float.parseFloat(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(),Config.ConfigurationParameterScope.cluster.toString(),hostVo.getClusterId()));
  Float cpuOvercommitRatio=Float.parseFloat(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(),Config.ConfigurationParameterScope.cluster.toString(),hostVo.getClusterId()));
  long minMemory=(long)(newServiceOffering.getRamSize() / memoryOvercommitRatio);
  ScaleVmCommand reconfigureCmd=new ScaleVmCommand(vm.getInstanceName(),newServiceOffering.getCpu(),(int)(newServiceOffering.getSpeed() / cpuOvercommitRatio),newServiceOffering.getSpeed(),minMemory * 1024L * 1024L,newServiceOffering.getRamSize() * 1024L * 1024L,newServiceOffering.getLimitCpuUse());
  Long dstHostId=vm.getHostId();
  ItWorkVO work=new ItWorkVO(UUID.randomUUID().toString(),_nodeId,State.Running,vm.getType(),vm.getId());
  work.setStep(Step.Prepare);
  work.setResourceType(ItWorkVO.ResourceType.Host);
  work.setResourceId(vm.getHostId());
  work=_workDao.persist(work);
  boolean success=false;
  try {
    if (reconfiguringOnExistingHost) {
      vm.setServiceOfferingId(oldServiceOffering.getId());
      _capacityMgr.releaseVmCapacity(vm,false,false,vm.getHostId());
      vm.setServiceOfferingId(newServiceofferingId);
      _capacityMgr.allocateVmCapacity(vm,false);
    }
    Answer reconfigureAnswer=_agentMgr.send(vm.getHostId(),reconfigureCmd);
    if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) {
      s_logger.error("String_Node_Str" + (reconfigureAnswer == null ? "String_Node_Str" : reconfigureAnswer.getDetails()));
      throw new CloudRuntimeException("String_Node_Str" + (reconfigureAnswer == null ? "String_Node_Str" : reconfigureAnswer.getDetails()));
    }
    success=true;
  }
 catch (  OperationTimedoutException e) {
    throw new AgentUnavailableException("String_Node_Str" + vm,dstHostId);
  }
catch (  AgentUnavailableException e) {
    throw e;
  }
 finally {
    if (!success) {
      _capacityMgr.releaseVmCapacity(vm,false,false,vm.getHostId());
      vm.setServiceOfferingId(oldServiceOffering.getId());
      _capacityMgr.allocateVmCapacity(vm,false);
    }
  }
  return vm;
}

Fixed version (ground truth):
@Override public VMInstanceVO reConfigureVm(String vmUuid,ServiceOffering oldServiceOffering,boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException {
  VMInstanceVO vm=_vmDao.findByUuid(vmUuid);
  long newServiceofferingId=vm.getServiceOfferingId();
  ServiceOffering newServiceOffering=_entityMgr.findById(ServiceOffering.class,newServiceofferingId);
  HostVO hostVo=_hostDao.findById(vm.getHostId());
  Float memoryOvercommitRatio=Float.parseFloat(_configServer.getConfigValue(Config.MemOverprovisioningFactor.key(),Config.ConfigurationParameterScope.cluster.toString(),hostVo.getClusterId()));
  Float cpuOvercommitRatio=Float.parseFloat(_configServer.getConfigValue(Config.CPUOverprovisioningFactor.key(),Config.ConfigurationParameterScope.cluster.toString(),hostVo.getClusterId()));
  long minMemory=(long)(newServiceOffering.getRamSize() / memoryOvercommitRatio);
  ScaleVmCommand reconfigureCmd=new ScaleVmCommand(vm.getInstanceName(),newServiceOffering.getCpu(),(int)(newServiceOffering.getSpeed() / cpuOvercommitRatio),newServiceOffering.getSpeed(),minMemory * 1024L * 1024L,newServiceOffering.getRamSize() * 1024L * 1024L,newServiceOffering.getLimitCpuUse());
  Long dstHostId=vm.getHostId();
  ItWorkVO work=new ItWorkVO(UUID.randomUUID().toString(),_nodeId,State.Running,vm.getType(),vm.getId());
  work.setStep(Step.Prepare);
  work.setResourceType(ItWorkVO.ResourceType.Host);
  work.setResourceId(vm.getHostId());
  work=_workDao.persist(work);
  boolean success=false;
  try {
    if (reconfiguringOnExistingHost) {
      vm.setServiceOfferingId(oldServiceOffering.getId());
      _capacityMgr.releaseVmCapacity(vm,false,false,vm.getHostId());
      vm.setServiceOfferingId(newServiceofferingId);
      _capacityMgr.allocateVmCapacity(vm,false);
    }
    Answer reconfigureAnswer=_agentMgr.send(vm.getHostId(),reconfigureCmd);
    if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) {
      s_logger.error("String_Node_Str" + (reconfigureAnswer == null ? "String_Node_Str" : reconfigureAnswer.getDetails()));
      throw new CloudRuntimeException("String_Node_Str" + (reconfigureAnswer == null ? "String_Node_Str" : reconfigureAnswer.getDetails()));
    }
    success=true;
  }
 catch (  OperationTimedoutException e) {
    throw new AgentUnavailableException("String_Node_Str" + vm,dstHostId);
  }
catch (  AgentUnavailableException e) {
    throw e;
  }
 finally {
    if (!success) {
      _capacityMgr.releaseVmCapacity(vm,false,false,vm.getHostId());
      vm.setServiceOfferingId(oldServiceOffering.getId());
      _capacityMgr.allocateVmCapacity(vm,false);
    }
  }
  return vm;
}