Program: 105138
Project: 105138
Buggy source:
@Override public void prepare(VirtualMachineProfile vm,DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException {
  if (dest == null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vm);
    }
    throw new CloudRuntimeException("String_Node_Str" + vm);
  }
  if (_volsDao.findByInstanceAndType(vm.getId(),Volume.Type.ROOT).isEmpty()) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  List<VolumeVO> vols=_volsDao.findUsableVolumesForInstance(vm.getId());
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + vols.size() + "String_Node_Str"+ vm);
  }
  List<VolumeTask> tasks=getTasks(vols,dest.getStorageForDisks(),vm);
  Volume vol=null;
  StoragePool pool=null;
  for (  VolumeTask task : tasks) {
    if (task.type == VolumeTaskType.NOP) {
      pool=(StoragePool)dataStoreMgr.getDataStore(task.pool.getId(),DataStoreRole.Primary);
      vol=task.volume;
    }
 else     if (task.type == VolumeTaskType.MIGRATE) {
      pool=(StoragePool)dataStoreMgr.getDataStore(task.pool.getId(),DataStoreRole.Primary);
      vol=migrateVolume(task.volume,pool);
    }
 else     if (task.type == VolumeTaskType.RECREATE) {
      Pair<VolumeVO,DataStore> result=recreateVolume(task.volume,vm,dest);
      pool=(StoragePool)dataStoreMgr.getDataStore(result.second().getId(),DataStoreRole.Primary);
      vol=result.first();
    }
    DataTO volumeTO=volFactory.getVolume(vol.getId()).getTO();
    DiskTO disk=new DiskTO(volumeTO,vol.getDeviceId(),vol.getPath(),vol.getVolumeType());
    VolumeInfo volumeInfo=volFactory.getVolume(vol.getId());
    DataStore dataStore=dataStoreMgr.getDataStore(vol.getPoolId(),DataStoreRole.Primary);
    disk.setDetails(getDetails(volumeInfo,dataStore));
    vm.addDisk(disk);
  }
}

Fixed version (ground truth):
@Override public void prepare(VirtualMachineProfile vm,DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException {
  if (dest == null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + vm);
    }
    throw new CloudRuntimeException("String_Node_Str" + vm);
  }
  if (_volsDao.findByInstanceAndType(vm.getId(),Volume.Type.ROOT).isEmpty()) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  List<VolumeVO> vols=_volsDao.findUsableVolumesForInstance(vm.getId());
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + vols.size() + "String_Node_Str"+ vm);
  }
  List<VolumeTask> tasks=getTasks(vols,dest.getStorageForDisks(),vm);
  Volume vol=null;
  StoragePool pool=null;
  for (  VolumeTask task : tasks) {
    if (task.type == VolumeTaskType.NOP) {
      pool=(StoragePool)dataStoreMgr.getDataStore(task.pool.getId(),DataStoreRole.Primary);
      vol=task.volume;
    }
 else     if (task.type == VolumeTaskType.MIGRATE) {
      pool=(StoragePool)dataStoreMgr.getDataStore(task.pool.getId(),DataStoreRole.Primary);
      vol=migrateVolume(task.volume,pool);
    }
 else     if (task.type == VolumeTaskType.RECREATE) {
      Pair<VolumeVO,DataStore> result=recreateVolume(task.volume,vm,dest);
      pool=(StoragePool)dataStoreMgr.getDataStore(result.second().getId(),DataStoreRole.Primary);
      vol=result.first();
    }
    VolumeInfo volumeInfo=volFactory.getVolume(vol.getId());
    DataTO volTO=volumeInfo.getTO();
    DiskTO disk=storageMgr.getDiskWithThrottling(volTO,vol.getVolumeType(),vol.getDeviceId(),vol.getPath(),vm.getServiceOfferingId(),vol.getDiskOfferingId());
    DataStore dataStore=dataStoreMgr.getDataStore(vol.getPoolId(),DataStoreRole.Primary);
    disk.setDetails(getDetails(volumeInfo,dataStore));
    vm.addDisk(disk);
  }
}