Program: 107227
Project: 107227
Buggy source:
@Override public void prepare(VirtualMachineProfile<? extends VirtualMachine> vm,DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException {
  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());
  int i=0;
  for (  VolumeVO vol : vols) {
    Volume.State state=vol.getState();
    if (state == Volume.State.Ready) {
      if (vol.getPoolId() == null) {
        s_logger.warn("String_Node_Str" + vol.getId() + "String_Node_Str");
        throw new StorageUnavailableException("String_Node_Str" + vol + "String_Node_Str",vol.getPoolId());
      }
      StoragePoolVO pool=_storagePoolDao.findById(vol.getPoolId());
      if (pool.getRemoved() != null || pool.isInMaintenance()) {
        if (vol.isRecreatable()) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + vol + "String_Node_Str"+ pool+ "String_Node_Str");
          }
          recreateVols.add(vol);
        }
 else {
          throw new StorageUnavailableException("String_Node_Str" + vol + "String_Node_Str",pool.getId());
        }
      }
 else {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + vol + "String_Node_Str");
        }
        vm.addDisk(new VolumeTO(vol,pool));
      }
    }
 else     if (state == Volume.State.Allocated) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + vol + "String_Node_Str");
      }
      recreateVols.add(vol);
    }
 else {
      throw new StorageUnavailableException("String_Node_Str" + vol + "String_Node_Str",vol.getPoolId());
    }
  }
  for (  VolumeVO vol : recreateVols) {
    VolumeVO newVol;
    if (vol.getState() == Volume.State.Allocated) {
      newVol=vol;
    }
 else {
      newVol=switchVolume(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);
    }
    created.first().setDeviceId(newVol.getDeviceId().intValue());
    newVol.setStatus(AsyncInstanceCreateStatus.Created);
    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 {
  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());
  int i=0;
  for (  VolumeVO vol : vols) {
    Volume.State state=vol.getState();
    if (state == Volume.State.Ready) {
      if (vol.getPoolId() == null) {
        s_logger.warn("String_Node_Str" + vol.getId() + "String_Node_Str");
        throw new StorageUnavailableException("String_Node_Str" + vol + "String_Node_Str",vol.getPoolId());
      }
      StoragePoolVO pool=_storagePoolDao.findById(vol.getPoolId());
      if (pool.getRemoved() != null || pool.isInMaintenance()) {
        if (vol.isRecreatable()) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + vol + "String_Node_Str"+ pool+ "String_Node_Str");
          }
          recreateVols.add(vol);
        }
 else {
          throw new StorageUnavailableException("String_Node_Str" + vol + "String_Node_Str",pool.getId());
        }
      }
 else {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + vol + "String_Node_Str");
        }
        vm.addDisk(new VolumeTO(vol,pool));
      }
    }
 else     if (state == Volume.State.Allocated) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + vol + "String_Node_Str");
      }
      recreateVols.add(vol);
    }
 else {
      throw new StorageUnavailableException("String_Node_Str" + vol + "String_Node_Str",vol.getPoolId());
    }
  }
  for (  VolumeVO vol : recreateVols) {
    VolumeVO newVol;
    if (vol.getState() == Volume.State.Allocated) {
      newVol=vol;
    }
 else {
      newVol=switchVolume(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.setStatus(AsyncInstanceCreateStatus.Created);
    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());
  }
}