Program: 107063
Project: 107063
Buggy source:
@Override public void prepare(VirtualMachineProfile<? extends VirtualMachine> vm,DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException {
  if (dest == null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vm);
    }
    throw new CloudRuntimeException("String_Node_Str" + vm);
  }
  List<VolumeVO> vols=_volsDao.findUsableVolumesForInstance(vm.getId());
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + vols.size() + "String_Node_Str"+ vm);
  }
  List<VolumeVO> recreateVols=new ArrayList<VolumeVO>(vols.size());
  for (  VolumeVO vol : vols) {
    StoragePool assignedPool=null;
    if (dest.getStorageForDisks() != null) {
      assignedPool=dest.getStorageForDisks().get(vol);
    }
    if (assignedPool != null) {
      Volume.State state=vol.getState();
      if (state == Volume.State.Allocated) {
        recreateVols.add(vol);
      }
 else {
        if (vol.isRecreatable()) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + vol + "String_Node_Str"+ assignedPool+ "String_Node_Str");
          }
          recreateVols.add(vol);
        }
 else {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + vol + "String_Node_Str"+ assignedPool);
          }
          throw new StorageUnavailableException("String_Node_Str" + vol,Volume.class,vol.getId());
        }
      }
    }
 else {
      if (vol.getPoolId() == null) {
        throw new StorageUnavailableException("String_Node_Str" + vol,Volume.class,vol.getId());
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + vol + "String_Node_Str"+ vol.getPoolId()+ "String_Node_Str");
      }
      StoragePoolVO pool=_storagePoolDao.findById(vol.getPoolId());
      vm.addDisk(new VolumeTO(vol,pool));
    }
  }
  for (  VolumeVO vol : recreateVols) {
    VolumeVO newVol;
    if (vol.getState() == Volume.State.Allocated) {
      vol.setRecreatable(true);
      newVol=vol;
    }
 else {
      newVol=switchVolume(vol,vm);
      newVol.setRecreatable(true);
      if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
        StoragePool poolWithOldVol=dest.getStorageForDisks().get(vol);
        dest.getStorageForDisks().put(newVol,poolWithOldVol);
        dest.getStorageForDisks().remove(vol);
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + newVol + "String_Node_Str"+ vol);
      }
    }
    try {
      _volsDao.update(newVol,Volume.Event.Create);
    }
 catch (    ConcurrentOperationException e) {
      throw new StorageUnavailableException("String_Node_Str" + newVol,newVol.getPoolId());
    }
    Pair<VolumeTO,StoragePool> created=createVolume(newVol,_diskOfferingDao.findById(newVol.getDiskOfferingId()),vm,vols,dest);
    if (created == null) {
      Long poolId=newVol.getPoolId();
      newVol.setPoolId(null);
      try {
        _volsDao.update(newVol,Volume.Event.OperationFailed);
      }
 catch (      ConcurrentOperationException e) {
        throw new CloudRuntimeException("String_Node_Str" + newVol,e);
      }
      throw new StorageUnavailableException("String_Node_Str" + newVol,poolId == null ? -1L : poolId);
    }
    created.first().setDeviceId(newVol.getDeviceId().intValue());
    newVol.setFolder(created.second().getPath());
    newVol.setPath(created.first().getPath());
    newVol.setSize(created.first().getSize());
    newVol.setPoolType(created.second().getPoolType());
    newVol.setPodId(created.second().getPodId());
    try {
      _volsDao.update(newVol,Volume.Event.OperationSucceeded);
    }
 catch (    ConcurrentOperationException e) {
      throw new CloudRuntimeException("String_Node_Str" + newVol,e);
    }
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + newVol + "String_Node_Str"+ created.second());
    }
    vm.addDisk(created.first());
  }
}

Fixed version (ground truth):
@Override public void prepare(VirtualMachineProfile<? extends VirtualMachine> vm,DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException {
  if (dest == null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vm);
    }
    throw new CloudRuntimeException("String_Node_Str" + vm);
  }
  List<VolumeVO> vols=_volsDao.findUsableVolumesForInstance(vm.getId());
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + vols.size() + "String_Node_Str"+ vm);
  }
  List<VolumeVO> recreateVols=new ArrayList<VolumeVO>(vols.size());
  for (  VolumeVO vol : vols) {
    StoragePool assignedPool=null;
    if (dest.getStorageForDisks() != null) {
      assignedPool=dest.getStorageForDisks().get(vol);
    }
    if (assignedPool != null) {
      Volume.State state=vol.getState();
      if (state == Volume.State.Allocated) {
        recreateVols.add(vol);
      }
 else {
        if (vol.isRecreatable()) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + vol + "String_Node_Str"+ assignedPool+ "String_Node_Str");
          }
          recreateVols.add(vol);
        }
 else {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + vol + "String_Node_Str"+ assignedPool);
          }
          throw new StorageUnavailableException("String_Node_Str" + vol,Volume.class,vol.getId());
        }
      }
    }
 else {
      if (vol.getPoolId() == null) {
        throw new StorageUnavailableException("String_Node_Str" + vol,Volume.class,vol.getId());
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + vol + "String_Node_Str"+ vol.getPoolId()+ "String_Node_Str");
      }
      StoragePoolVO pool=_storagePoolDao.findById(vol.getPoolId());
      vm.addDisk(new VolumeTO(vol,pool));
    }
  }
  for (  VolumeVO vol : recreateVols) {
    VolumeVO newVol;
    if (vol.getState() == Volume.State.Allocated) {
      newVol=vol;
    }
 else {
      newVol=switchVolume(vol,vm);
      if (dest.getStorageForDisks() != null && dest.getStorageForDisks().containsKey(vol)) {
        StoragePool poolWithOldVol=dest.getStorageForDisks().get(vol);
        dest.getStorageForDisks().put(newVol,poolWithOldVol);
        dest.getStorageForDisks().remove(vol);
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + newVol + "String_Node_Str"+ vol);
      }
    }
    try {
      _volsDao.update(newVol,Volume.Event.Create);
    }
 catch (    ConcurrentOperationException e) {
      throw new StorageUnavailableException("String_Node_Str" + newVol,newVol.getPoolId());
    }
    Pair<VolumeTO,StoragePool> created=createVolume(newVol,_diskOfferingDao.findById(newVol.getDiskOfferingId()),vm,vols,dest);
    if (created == null) {
      Long poolId=newVol.getPoolId();
      newVol.setPoolId(null);
      try {
        _volsDao.update(newVol,Volume.Event.OperationFailed);
      }
 catch (      ConcurrentOperationException e) {
        throw new CloudRuntimeException("String_Node_Str" + newVol,e);
      }
      throw new StorageUnavailableException("String_Node_Str" + newVol,poolId == null ? -1L : poolId);
    }
    created.first().setDeviceId(newVol.getDeviceId().intValue());
    newVol.setFolder(created.second().getPath());
    newVol.setPath(created.first().getPath());
    newVol.setSize(created.first().getSize());
    newVol.setPoolType(created.second().getPoolType());
    newVol.setPodId(created.second().getPodId());
    try {
      _volsDao.update(newVol,Volume.Event.OperationSucceeded);
    }
 catch (    ConcurrentOperationException e) {
      throw new CloudRuntimeException("String_Node_Str" + newVol,e);
    }
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + newVol + "String_Node_Str"+ created.second());
    }
    vm.addDisk(created.first());
  }
}