Program: 107213
Project: 107213
Buggy source:
@Override @DB public synchronized StoragePoolVO cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ServerApiException {
  Long primaryStorageId=cmd.getId();
  Long userId=UserContext.current().getCallerUserId();
  StoragePoolVO primaryStorage=null;
  try {
    Transaction.currentTxn();
    primaryStorage=_storagePoolDao.acquireInLockTable(primaryStorageId);
    if (primaryStorage == null) {
      String msg="String_Node_Str";
      s_logger.error(msg);
      throw new ExecutionException(msg);
    }
    if (primaryStorage.getStatus().equals(Status.Up) || primaryStorage.getStatus().equals(Status.PrepareForMaintenance)) {
      throw new StorageUnavailableException("String_Node_Str" + primaryStorageId + "String_Node_Str"+ primaryStorage.getStatus().toString(),primaryStorageId);
    }
    primaryStorage.setStatus(Status.CancelMaintenance);
    _storagePoolDao.persist(primaryStorage);
    List<VolumeVO> allVolumes=_volsDao.findByPoolId(primaryStorageId);
    for (    VolumeVO volume : allVolumes) {
      if ((!volume.destroyed) && (volume.removed == null)) {
        VMInstanceVO vmInstance=_vmInstanceDao.findById(volume.getInstanceId());
        if (vmInstance.getState().equals(State.Stopping) || vmInstance.getState().equals(State.Stopped)) {
          if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
            if (_consoleProxyMgr.startProxy(vmInstance.getId()) == null) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg);
              throw new ExecutionException(msg);
            }
          }
          if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
            if (_secStorageMgr.startSecStorageVm(vmInstance.getId()) == null) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg);
              throw new ExecutionException(msg);
            }
          }
          if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
            try {
              if (_userVmMgr.startUserVm(vmInstance.getId()) == null) {
                String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
                s_logger.warn(msg);
                throw new ExecutionException(msg);
              }
            }
 catch (            StorageUnavailableException e) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg,e);
              throw new ExecutionException(msg);
            }
catch (            InsufficientCapacityException e) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg,e);
              throw new ExecutionException(msg);
            }
catch (            ConcurrentOperationException e) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg,e);
              primaryStorage.setStatus(Status.ErrorInMaintenance);
              _storagePoolDao.persist(primaryStorage);
              throw new ExecutionException(msg);
            }
catch (            ExecutionException e) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg,e);
              throw new ExecutionException(msg);
            }
          }
        }
      }
    }
    try {
      _configMgr.updateConfiguration(userId,"String_Node_Str","String_Node_Str");
    }
 catch (    InvalidParameterValueException e) {
      String msg="String_Node_Str";
      s_logger.warn(msg,e);
      throw new ExecutionException(msg);
    }
catch (    CloudRuntimeException e) {
      String msg="String_Node_Str";
      s_logger.warn(msg,e);
      throw new ExecutionException(msg);
    }
    primaryStorage.setStatus(Status.Up);
    _storagePoolDao.persist(primaryStorage);
    return primaryStorage;
  }
 catch (  Exception e) {
    primaryStorage.setStatus(Status.ErrorInMaintenance);
    _storagePoolDao.persist(primaryStorage);
    if (e instanceof ExecutionException) {
      throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR,e.getMessage());
    }
 else     if (e instanceof InvalidParameterValueException) {
      throw new ServerApiException(BaseCmd.PARAM_ERROR,e.getMessage());
    }
 else {
      throw new ServerApiException(BaseCmd.INTERNAL_ERROR,e.getMessage());
    }
  }
 finally {
    _storagePoolDao.releaseFromLockTable(primaryStorage.getId());
  }
}

Fixed version (ground truth):
@Override @DB public synchronized StoragePoolVO cancelPrimaryStorageForMaintenance(CancelPrimaryStorageMaintenanceCmd cmd) throws ServerApiException {
  Long primaryStorageId=cmd.getId();
  Long userId=UserContext.current().getCallerUserId();
  StoragePoolVO primaryStorage=null;
  try {
    Transaction.currentTxn();
    primaryStorage=_storagePoolDao.acquireInLockTable(primaryStorageId);
    if (primaryStorage == null) {
      String msg="String_Node_Str";
      s_logger.error(msg);
      throw new ExecutionException(msg);
    }
    if (primaryStorage.getStatus().equals(Status.Up) || primaryStorage.getStatus().equals(Status.PrepareForMaintenance)) {
      throw new StorageUnavailableException("String_Node_Str" + primaryStorageId + "String_Node_Str"+ primaryStorage.getStatus().toString(),primaryStorageId);
    }
    primaryStorage.setStatus(Status.CancelMaintenance);
    _storagePoolDao.persist(primaryStorage);
    List<VolumeVO> allVolumes=_volsDao.findByPoolId(primaryStorageId);
    for (    VolumeVO volume : allVolumes) {
      if ((!volume.destroyed) && (volume.removed == null)) {
        VMInstanceVO vmInstance=_vmInstanceDao.findById(volume.getInstanceId());
        if (vmInstance.getState().equals(State.Stopping) || vmInstance.getState().equals(State.Stopped)) {
          if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
            if (_consoleProxyMgr.startProxy(vmInstance.getId()) == null) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg);
              throw new ExecutionException(msg);
            }
          }
          if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
            if (_secStorageMgr.startSecStorageVm(vmInstance.getId()) == null) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg);
              throw new ExecutionException(msg);
            }
          }
          if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
            try {
              if (_userVmMgr.startUserVm(vmInstance.getId()) == null) {
                String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
                s_logger.warn(msg);
                throw new ExecutionException(msg);
              }
            }
 catch (            StorageUnavailableException e) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg,e);
              throw new ExecutionException(msg);
            }
catch (            InsufficientCapacityException e) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg,e);
              throw new ExecutionException(msg);
            }
catch (            ConcurrentOperationException e) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg,e);
              setPoolStateToError(primaryStorage);
              throw new ExecutionException(msg);
            }
catch (            ExecutionException e) {
              String msg="String_Node_Str" + vmInstance.getId() + "String_Node_Str";
              s_logger.warn(msg,e);
              throw new ExecutionException(msg);
            }
          }
        }
      }
    }
    try {
      _configMgr.updateConfiguration(userId,"String_Node_Str","String_Node_Str");
    }
 catch (    InvalidParameterValueException e) {
      String msg="String_Node_Str";
      s_logger.warn(msg,e);
      throw new ExecutionException(msg);
    }
catch (    CloudRuntimeException e) {
      String msg="String_Node_Str";
      s_logger.warn(msg,e);
      throw new ExecutionException(msg);
    }
    primaryStorage.setStatus(Status.Up);
    _storagePoolDao.persist(primaryStorage);
    return primaryStorage;
  }
 catch (  Exception e) {
    setPoolStateToError(primaryStorage);
    if (e instanceof ExecutionException) {
      throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR,e.getMessage());
    }
 else     if (e instanceof InvalidParameterValueException) {
      throw new ServerApiException(BaseCmd.PARAM_ERROR,e.getMessage());
    }
 else {
      throw new ServerApiException(BaseCmd.INTERNAL_ERROR,e.getMessage());
    }
  }
 finally {
    _storagePoolDao.releaseFromLockTable(primaryStorage.getId());
  }
}