Program: 89942
Project: 89942
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) {
      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);
        }
      }
 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);
    }
  }
  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);
    }
    Pair<VolumeTO,StoragePool> created=createVolume(newVol,_diskOfferingDao.findById(newVol.getDiskOfferingId()),vm,vols,dest);
    if (created == null) {
      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,newVol);
    }
    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) {
      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);
        }
      }
 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);
    }
  }
  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);
    }
    Pair<VolumeTO,StoragePool> created=createVolume(newVol,_diskOfferingDao.findById(newVol.getDiskOfferingId()),vm,vols,dest);
    if (created == null) {
      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,newVol);
    }
    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());
  }
}