Program: 107372
Project: 107372
Buggy source:
@DB protected List<VolumeVO> create(Account account,VMInstanceVO vm,VMTemplateVO template,DataCenterVO dc,HostPodVO pod,ServiceOfferingVO offering,DiskOfferingVO diskOffering,List<StoragePoolVO> avoids,long size){
  ArrayList<VolumeVO> vols=new ArrayList<VolumeVO>(2);
  VolumeVO dataVol=null;
  VolumeVO rootVol=null;
  Transaction txn=Transaction.currentTxn();
  txn.start();
  if (Storage.ImageFormat.ISO == template.getFormat()) {
    rootVol=new VolumeVO(VolumeType.ROOT,vm.getId(),vm.getInstanceName() + "String_Node_Str",dc.getId(),pod.getId(),account.getId(),account.getDomainId(),(size > 0) ? size : diskOffering.getDiskSizeInBytes());
    createStartedEvent(account,rootVol);
    rootVol.setDiskOfferingId(diskOffering.getId());
    rootVol.setSourceType(SourceType.Template);
    rootVol.setSourceId(template.getId());
    rootVol.setDeviceId(0l);
    rootVol=_volsDao.persist(rootVol);
  }
 else {
    rootVol=new VolumeVO(VolumeType.ROOT,vm.getId(),template.getId(),vm.getInstanceName() + "String_Node_Str",dc.getId(),pod.getId(),account.getId(),account.getDomainId(),offering.isRecreatable());
    createStartedEvent(account,rootVol);
    rootVol.setDiskOfferingId(offering.getId());
    rootVol.setTemplateId(template.getId());
    rootVol.setSourceId(template.getId());
    rootVol.setSourceType(SourceType.Template);
    rootVol.setDeviceId(0l);
    rootVol=_volsDao.persist(rootVol);
    if ((diskOffering != null && diskOffering.getDiskSizeInBytes() > 0)) {
      dataVol=new VolumeVO(VolumeType.DATADISK,vm.getId(),vm.getInstanceName() + "String_Node_Str",dc.getId(),pod.getId(),account.getId(),account.getDomainId(),(size > 0) ? size : diskOffering.getDiskSizeInBytes());
      createStartedEvent(account,dataVol);
      dataVol.setDiskOfferingId(diskOffering.getId());
      dataVol.setSourceType(SourceType.DiskOffering);
      dataVol.setSourceId(diskOffering.getId());
      dataVol.setDeviceId(1l);
      dataVol=_volsDao.persist(dataVol);
    }
  }
  txn.commit();
  VolumeVO dataCreated=null;
  VolumeVO rootCreated=null;
  try {
    rootCreated=createVolume(rootVol,vm,template,dc,pod,null,offering,diskOffering,avoids,size,template.getHypervisorType());
    if (rootCreated == null) {
      throw new CloudRuntimeException("String_Node_Str" + rootVol);
    }
    vols.add(rootCreated);
    if (dataVol != null) {
      StoragePoolVO pool=_storagePoolDao.findById(rootCreated.getPoolId());
      dataCreated=createVolume(dataVol,vm,null,dc,pod,pool.getClusterId(),offering,diskOffering,avoids,size,template.getHypervisorType());
      if (dataCreated == null) {
        throw new CloudRuntimeException("String_Node_Str" + dataVol);
      }
      vols.add(dataCreated);
    }
    return vols;
  }
 catch (  Exception e) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(e.getMessage());
    }
    if (rootCreated != null) {
      destroyVolume(rootCreated);
    }
    throw new CloudRuntimeException("String_Node_Str" + vm,e);
  }
}

Fixed version (ground truth):
@DB protected List<VolumeVO> create(Account account,VMInstanceVO vm,VMTemplateVO template,DataCenterVO dc,HostPodVO pod,ServiceOfferingVO offering,DiskOfferingVO diskOffering,List<StoragePoolVO> avoids,long size){
  ArrayList<VolumeVO> vols=new ArrayList<VolumeVO>(2);
  VolumeVO dataVol=null;
  VolumeVO rootVol=null;
  Transaction txn=Transaction.currentTxn();
  txn.start();
  if (Storage.ImageFormat.ISO == template.getFormat()) {
    rootVol=new VolumeVO(VolumeType.ROOT,vm.getId(),vm.getInstanceName() + "String_Node_Str",dc.getId(),pod.getId(),account.getId(),account.getDomainId(),(size > 0) ? size : diskOffering.getDiskSizeInBytes());
    createStartedEvent(account,rootVol);
    rootVol.setDiskOfferingId(diskOffering.getId());
    rootVol.setSourceType(SourceType.Template);
    rootVol.setSourceId(template.getId());
    rootVol.setDeviceId(0l);
    rootVol=_volsDao.persist(rootVol);
  }
 else {
    rootVol=new VolumeVO(VolumeType.ROOT,vm.getId(),template.getId(),vm.getInstanceName() + "String_Node_Str",dc.getId(),pod.getId(),account.getId(),account.getDomainId(),offering.isRecreatable());
    createStartedEvent(account,rootVol);
    rootVol.setDiskOfferingId(offering.getId());
    rootVol.setTemplateId(template.getId());
    rootVol.setSourceId(template.getId());
    rootVol.setSourceType(SourceType.Template);
    rootVol.setDeviceId(0l);
    rootVol=_volsDao.persist(rootVol);
    if ((diskOffering != null && diskOffering.getDiskSizeInBytes() > 0) || (diskOffering != null && diskOffering.isCustomized())) {
      dataVol=new VolumeVO(VolumeType.DATADISK,vm.getId(),vm.getInstanceName() + "String_Node_Str",dc.getId(),pod.getId(),account.getId(),account.getDomainId(),(size > 0) ? size : diskOffering.getDiskSizeInBytes());
      createStartedEvent(account,dataVol);
      dataVol.setDiskOfferingId(diskOffering.getId());
      dataVol.setSourceType(SourceType.DiskOffering);
      dataVol.setSourceId(diskOffering.getId());
      dataVol.setDeviceId(1l);
      dataVol=_volsDao.persist(dataVol);
    }
  }
  txn.commit();
  VolumeVO dataCreated=null;
  VolumeVO rootCreated=null;
  try {
    rootCreated=createVolume(rootVol,vm,template,dc,pod,null,offering,diskOffering,avoids,size,template.getHypervisorType());
    if (rootCreated == null) {
      throw new CloudRuntimeException("String_Node_Str" + rootVol);
    }
    vols.add(rootCreated);
    if (dataVol != null) {
      StoragePoolVO pool=_storagePoolDao.findById(rootCreated.getPoolId());
      dataCreated=createVolume(dataVol,vm,null,dc,pod,pool.getClusterId(),offering,diskOffering,avoids,size,template.getHypervisorType());
      if (dataCreated == null) {
        throw new CloudRuntimeException("String_Node_Str" + dataVol);
      }
      vols.add(dataCreated);
    }
    return vols;
  }
 catch (  Exception e) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(e.getMessage());
    }
    if (rootCreated != null) {
      destroyVolume(rootCreated);
    }
    throw new CloudRuntimeException("String_Node_Str" + vm,e);
  }
}