Program: 105706
Project: 105706
Buggy source:
@Override public VolumeInfo createVolumeOnPrimaryStorage(VirtualMachine vm,VolumeInfo volume,HypervisorType rootDiskHyperType,StoragePool storagePool) throws NoTransitionException {
  VirtualMachineTemplate rootDiskTmplt=_entityMgr.findById(VirtualMachineTemplate.class,vm.getTemplateId());
  DataCenter dcVO=_entityMgr.findById(DataCenter.class,vm.getDataCenterId());
  Pod pod=_entityMgr.findById(Pod.class,storagePool.getPodId());
  ServiceOffering svo=_entityMgr.findById(ServiceOffering.class,vm.getServiceOfferingId());
  DiskOffering diskVO=_entityMgr.findById(DiskOffering.class,volume.getDiskOfferingId());
  Long clusterId=(storagePool == null ? null : storagePool.getClusterId());
  VolumeInfo vol=null;
  if (volume.getState() == Volume.State.Allocated) {
    vol=createVolume(volume,vm,rootDiskTmplt,dcVO,pod,clusterId,svo,diskVO,new ArrayList<StoragePool>(),volume.getSize(),rootDiskHyperType);
  }
 else   if (volume.getState() == Volume.State.Uploaded) {
    vol=copyVolume(storagePool,volume,vm,rootDiskTmplt,dcVO,pod,diskVO,svo,rootDiskHyperType);
    if (vol != null) {
      _resourceLimitMgr.decrementResourceCount(volume.getAccountId(),ResourceType.secondary_storage,volume.getSize());
      _resourceLimitMgr.incrementResourceCount(volume.getAccountId(),ResourceType.primary_storage,volume.getSize());
    }
  }
  if (vol == null) {
    throw new CloudRuntimeException("String_Node_Str" + volume.getId());
  }
  VolumeVO volVO=_volsDao.findById(vol.getId());
  if (volVO.getFormat() == null) {
    volVO.setFormat(getSupportedImageFormatForCluster(rootDiskHyperType));
  }
  _volsDao.update(volVO.getId(),volVO);
  return volFactory.getVolume(volVO.getId());
}

Fixed version (ground truth):
@Override public VolumeInfo createVolumeOnPrimaryStorage(VirtualMachine vm,VolumeInfo volume,HypervisorType rootDiskHyperType,StoragePool storagePool) throws NoTransitionException {
  VirtualMachineTemplate rootDiskTmplt=_entityMgr.findById(VirtualMachineTemplate.class,vm.getTemplateId());
  DataCenter dcVO=_entityMgr.findById(DataCenter.class,vm.getDataCenterId());
  Pod pod=_entityMgr.findById(Pod.class,storagePool.getPodId());
  ServiceOffering svo=_entityMgr.findById(ServiceOffering.class,vm.getServiceOfferingId());
  DiskOffering diskVO=_entityMgr.findById(DiskOffering.class,volume.getDiskOfferingId());
  Long clusterId=storagePool.getClusterId();
  VolumeInfo vol=null;
  if (volume.getState() == Volume.State.Allocated) {
    vol=createVolume(volume,vm,rootDiskTmplt,dcVO,pod,clusterId,svo,diskVO,new ArrayList<StoragePool>(),volume.getSize(),rootDiskHyperType);
  }
 else   if (volume.getState() == Volume.State.Uploaded) {
    vol=copyVolume(storagePool,volume,vm,rootDiskTmplt,dcVO,pod,diskVO,svo,rootDiskHyperType);
    if (vol != null) {
      _resourceLimitMgr.decrementResourceCount(volume.getAccountId(),ResourceType.secondary_storage,volume.getSize());
      _resourceLimitMgr.incrementResourceCount(volume.getAccountId(),ResourceType.primary_storage,volume.getSize());
    }
  }
  if (vol == null) {
    throw new CloudRuntimeException("String_Node_Str" + volume.getId());
  }
  VolumeVO volVO=_volsDao.findById(vol.getId());
  if (volVO.getFormat() == null) {
    volVO.setFormat(getSupportedImageFormatForCluster(rootDiskHyperType));
  }
  _volsDao.update(volVO.getId(),volVO);
  return volFactory.getVolume(volVO.getId());
}