Revert "use more Reference::query instead of UNO_QUERY_THROW"

This reverts commit 7fc6063914.

sberg noticed that there is a difference now:

there's a subtle difference now, in that if  y  was null originally, it would have thrown a (caught) exception, whereas now it will crash in the  y.query<X>()  call.

Change-Id: Idbb5a08d635d15b5ca63f4822eddf05fb0a5afa0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156002
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2023-08-25 14:15:56 +02:00
parent 139cffc531
commit 87db52ab1e
54 changed files with 408 additions and 167 deletions
+2 -2
View File
@@ -395,8 +395,8 @@ static uno::Reference< vba::XVBACompatibility > getVBACompatibility( const uno::
uno::Reference< vba::XVBACompatibility > xVBACompat;
try
{
if (auto xModelProps = rxModel.query<beans::XPropertySet>() )
xVBACompat.set( xModelProps->getPropertyValue( "BasicLibraries" ), uno::UNO_QUERY );
uno::Reference< beans::XPropertySet > xModelProps( rxModel, uno::UNO_QUERY_THROW );
xVBACompat.set( xModelProps->getPropertyValue( "BasicLibraries" ), uno::UNO_QUERY );
}
catch(const uno::Exception& )
{
@@ -1477,9 +1477,9 @@ bool EmbeddedObjectContainer::SetPersistentEntries(const uno::Reference< embed::
// if this method is used as part of SaveCompleted the object must stay unmodified after execution
try
{
if (auto xModif = xObj->getComponent().query<util::XModifiable>() )
if ( xModif->isModified() )
xModif->setModified( false );
uno::Reference< util::XModifiable > xModif( xObj->getComponent(), uno::UNO_QUERY_THROW );
if ( xModif->isModified() )
xModif->setModified( false );
}
catch (const uno::Exception&)
{
+6 -1
View File
@@ -238,8 +238,13 @@ void OLockListener::Dispose()
if ( nMode & embed::Actions::PREVENT_TERMINATION )
{
if (auto xDesktop = xInstance.query<frame::XDesktop>() )
try
{
uno::Reference< frame::XDesktop > xDesktop( xInstance, uno::UNO_QUERY_THROW );
xDesktop->removeTerminateListener( static_cast< frame::XTerminateListener* >( this ) );
}
catch( uno::Exception& )
{}
}
}
+2 -2
View File
@@ -679,8 +679,8 @@ OUString OStorageHelper::GetODFVersionFromStorage(const uno::Reference<embed::XS
OUString aODFVersion;
try
{
if (auto xPropSet = xStorage.query<beans::XPropertySet>())
xPropSet->getPropertyValue("Version") >>= aODFVersion;
uno::Reference<beans::XPropertySet> xPropSet(xStorage, uno::UNO_QUERY_THROW);
xPropSet->getPropertyValue("Version") >>= aODFVersion;
}
catch (uno::Exception&)
{
+27 -4
View File
@@ -603,14 +603,31 @@ void DocumentHolder::FreeOffice()
void DocumentHolder::DisconnectFrameDocument( bool bComplete )
{
if (auto xModifiable = m_xDocument.query<util::XModifyBroadcaster>() )
try
{
uno::Reference< util::XModifyBroadcaster > xModifiable( m_xDocument, uno::UNO_QUERY_THROW );
xModifiable->removeModifyListener( static_cast<util::XModifyListener*>(this) );
}
catch( const uno::Exception& )
{}
if (auto xBroadcaster = m_xDocument.query<util::XCloseBroadcaster>() )
try
{
uno::Reference< util::XCloseBroadcaster > xBroadcaster(
m_xDocument, uno::UNO_QUERY_THROW );
xBroadcaster->removeCloseListener( static_cast<util::XCloseListener*>(this) );
}
catch( const uno::Exception& )
{}
if (auto xBroadcaster = m_xFrame.query<util::XCloseBroadcaster>() )
try
{
uno::Reference< util::XCloseBroadcaster > xBroadcaster(
m_xFrame, uno::UNO_QUERY_THROW );
xBroadcaster->removeCloseListener( static_cast<util::XCloseListener*>(this) );
}
catch( const uno::Exception& )
{}
if ( bComplete )
{
@@ -644,8 +661,14 @@ void DocumentHolder::CloseDocument()
void DocumentHolder::CloseFrame()
{
if (auto xBroadcaster = m_xFrame.query<util::XCloseBroadcaster>() )
try
{
uno::Reference< util::XCloseBroadcaster > xBroadcaster(
m_xFrame, uno::UNO_QUERY_THROW );
xBroadcaster->removeCloseListener( static_cast<util::XCloseListener*>(this) );
}
catch( const uno::Exception& )
{}
uno::Reference<util::XCloseable> xCloseable(
m_xFrame,uno::UNO_QUERY);
+7 -1
View File
@@ -277,9 +277,15 @@ void ConverterRoot::registerTitleLayout( const Reference< XTitle >& rxTitle,
void ConverterRoot::convertTitlePositions()
{
if (auto xChart1Doc = mxData->mxDoc.query<cssc::XChartDocument>() )
try
{
Reference< cssc::XChartDocument > xChart1Doc( mxData->mxDoc, UNO_QUERY_THROW );
for (auto & title : mxData->maTitles)
title.second.convertTitlePos( *this, xChart1Doc );
}
catch( Exception& )
{
}
}
namespace {
+7 -1
View File
@@ -74,8 +74,14 @@ OleObjectHelper::OleObjectHelper(
OleObjectHelper::~OleObjectHelper()
{
if (auto xResolverComp = mxResolver.query<XComponent>() )
try
{
Reference< XComponent > xResolverComp( mxResolver, UNO_QUERY_THROW );
xResolverComp->dispose();
}
catch(const Exception& )
{
}
}
// TODO: this is probably a sub-optimal approach: ideally the media type
+7 -1
View File
@@ -323,8 +323,14 @@ void VbaModule::createModule( std::u16string_view rVBASourceCode,
aSourceCode.append( "End Sub\n" );
// insert extended module info
if (auto xVBAModuleInfo = rxBasicLib.query<XVBAModuleInfo>() )
try
{
Reference< XVBAModuleInfo > xVBAModuleInfo( rxBasicLib, UNO_QUERY_THROW );
xVBAModuleInfo->insertModuleInfo( maName, aModuleInfo );
}
catch (const Exception&)
{
}
// insert the module into the passed Basic library
try
+9 -4
View File
@@ -3988,10 +3988,15 @@ void XclImpChChart::Convert( const Reference<XChartDocument>& xChartDoc,
}
// chart title
if( mxTitle )
if (auto xTitled = xChartDoc.query<XTitled>() )
if (auto xTitle = mxTitle->CreateTitle().query<XTitle>() )
xTitled->setTitleObject( xTitle );
if( mxTitle ) try
{
Reference< XTitled > xTitled( xChartDoc, UNO_QUERY_THROW );
Reference< XTitle > xTitle( mxTitle->CreateTitle(), UNO_SET_THROW );
xTitled->setTitleObject( xTitle );
}
catch( Exception& )
{
}
/* Create the diagram object and attach it to the chart document. Currently,
one diagram is used to carry all coordinate systems and data series. */
+2 -2
View File
@@ -159,8 +159,8 @@ bool ScfPropertySet::HasProperty( const OUString& rPropName ) const
bool bHasProp = false;
try
{
if (auto xPropState = mxPropSet.query<XPropertyState>() )
bHasProp = xPropState->getPropertyState( rPropName ) == css::beans::PropertyState_DIRECT_VALUE;
Reference< XPropertyState > xPropState( mxPropSet, UNO_QUERY_THROW );
bHasProp = xPropState->getPropertyState( rPropName ) == css::beans::PropertyState_DIRECT_VALUE;
}
catch( Exception& )
{
+7 -1
View File
@@ -1866,8 +1866,14 @@ private:
NumberFormatFinalizer::NumberFormatFinalizer( const WorkbookHelper& rHelper ) :
maEnUsLocale( "en", "US", OUString() )
{
if (auto xNumFmtsSupp = rHelper.getDocument().query<XNumberFormatsSupplier>() )
try
{
Reference< XNumberFormatsSupplier > xNumFmtsSupp( rHelper.getDocument(), UNO_QUERY_THROW );
mxNumFmts = xNumFmtsSupp->getNumberFormats();
}
catch( Exception& )
{
}
OSL_ENSURE( mxNumFmts.is(), "NumberFormatFinalizer::NumberFormatFinalizer - cannot get number formats" );
}
+7 -1
View File
@@ -646,8 +646,14 @@ OUString PivotCacheField::createDateGroupField( const Reference< XDataPilotField
default: OSL_FAIL( "PivotCacheField::convertRangeGrouping - unknown date/time interval" );
}
if (auto xDPGrouping = rxBaseDPField.query<XDataPilotFieldGrouping>() )
try
{
Reference< XDataPilotFieldGrouping > xDPGrouping( rxBaseDPField, UNO_QUERY_THROW );
xDPGroupField = xDPGrouping->createDateGroup( aGroupInfo );
}
catch( Exception& )
{
}
}
Reference< XNamed > xFieldName( xDPGroupField, UNO_QUERY );
+7 -1
View File
@@ -1409,8 +1409,14 @@ Reference< XDataPilotField > PivotTable::getDataPilotField( sal_Int32 nFieldIdx
Reference< XDataPilotField > PivotTable::getDataLayoutField() const
{
Reference< XDataPilotField > xDPField;
if (auto xDPDataFieldSupp = mxDPDescriptor.query<XDataPilotDataLayoutFieldSupplier>() )
try
{
Reference< XDataPilotDataLayoutFieldSupplier > xDPDataFieldSupp( mxDPDescriptor, UNO_QUERY_THROW );
xDPField = xDPDataFieldSupp->getDataLayoutField();
}
catch( Exception& )
{
}
return xDPField;
}
+7 -2
View File
@@ -527,8 +527,13 @@ Reference< XCellRange > WorksheetGlobals::getRow( sal_Int32 nRow ) const
Reference< XDrawPage > WorksheetGlobals::getDrawPage() const
{
Reference< XDrawPage > xDrawPage;
if (auto xSupplier = mxSheet.query<XDrawPageSupplier>())
xDrawPage = xSupplier->getDrawPage();
try
{
xDrawPage = Reference< XDrawPageSupplier >( mxSheet, UNO_QUERY_THROW )->getDrawPage();
}
catch( Exception& )
{
}
return xDrawPage;
}
+6 -5
View File
@@ -568,9 +568,9 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, ErrCode& rError )
VBA Globals object and does all related initialization. */
if ( xModelSet.is() ) try
{
if (auto xVBACompat = xModelSet->getPropertyValue(
"BasicLibraries" ).query<script::vba::XVBACompatibility>() )
xVBACompat->setVBACompatibilityMode( true );
uno::Reference< script::vba::XVBACompatibility > xVBACompat( xModelSet->getPropertyValue(
"BasicLibraries" ), uno::UNO_QUERY_THROW );
xVBACompat->setVBACompatibilityMode( true );
}
catch( const uno::Exception& )
{
@@ -853,8 +853,9 @@ bool ScXMLImportWrapper::Export(bool bStylesOnly)
&& aVersion != ODFVER_010_TEXT
&& aVersion != ODFVER_011_TEXT )
{
if (auto xDMA = xModel.query<rdf::XDocumentMetadataAccess>() )
xDMA->storeMetadataToStorage( xStorage );
const uno::Reference< rdf::XDocumentMetadataAccess > xDMA(
xModel, uno::UNO_QUERY_THROW );
xDMA->storeMetadataToStorage( xStorage );
}
}
catch ( const beans::UnknownPropertyException &)
+7 -1
View File
@@ -999,8 +999,14 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
TOOLS_WARN_EXCEPTION( "sc", "SfxEventHintId::SaveDoc" );
SC_MOD()->SetInSharedDocSaving( false );
if (auto xClose = xModel.query<util::XCloseable>() )
try
{
uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
xClose->close( true );
}
catch ( uno::Exception& )
{
}
}
}
+7 -1
View File
@@ -1174,8 +1174,14 @@ void ScDocShell::Execute( SfxRequest& rReq )
TOOLS_WARN_EXCEPTION( "sc", "SID_SHARE_DOC" );
SC_MOD()->SetInSharedDocSaving( false );
if (auto xClose = xModel.query<util::XCloseable>() )
try
{
uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
xClose->close( true );
}
catch ( uno::Exception& )
{
}
}
}
}
+14 -2
View File
@@ -425,14 +425,26 @@ void SAL_CALL ScVbaEventListener::disposing( const lang::EventObject& rEvent )
void ScVbaEventListener::startModelListening()
{
if (auto xChangesNotifier = mxModel.query<util::XChangesNotifier>() )
try
{
uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW );
xChangesNotifier->addChangesListener( this );
}
catch( uno::Exception& )
{
}
}
void ScVbaEventListener::stopModelListening()
{
if (auto xChangesNotifier = mxModel.query<util::XChangesNotifier>() )
try
{
uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW );
xChangesNotifier->removeChangesListener( this );
}
catch( uno::Exception& )
{
}
}
uno::Reference< frame::XController > ScVbaEventListener::getControllerForWindow( vcl::Window* pWindow ) const
+8 -1
View File
@@ -353,8 +353,15 @@ ScriptEventHelper::~ScriptEventHelper()
// dispose control ( and remove any associated event registrations )
if ( m_bDispose )
{
if (auto xComp = m_xControl.query<lang::XComponent>() )
try
{
uno::Reference< lang::XComponent > xComp( m_xControl, uno::UNO_QUERY_THROW );
xComp->dispose();
}
// destructor can't throw
catch( uno::Exception& )
{
}
}
}
+11 -4
View File
@@ -36,10 +36,17 @@ Reference<presentation::XSlideShowController> PresenterHelper::GetSlideShowContr
{
Reference<presentation::XSlideShowController> xSlideShowController;
if( rxController.is() )
if (auto xPS = rxController->getModel().query<XPresentationSupplier>())
if (auto xPresentation = xPS->getPresentation().query<XPresentation2>())
xSlideShowController = xPresentation->getController();
if( rxController.is() ) try
{
Reference<XPresentationSupplier> xPS ( rxController->getModel(), UNO_QUERY_THROW);
Reference<XPresentation2> xPresentation(xPS->getPresentation(), UNO_QUERY_THROW);
xSlideShowController = xPresentation->getController();
}
catch(RuntimeException&)
{
}
return xSlideShowController;
}
+2 -2
View File
@@ -411,8 +411,8 @@ void PresenterScreen::SwitchMonitors()
nNewScreen++; // otherwise we store screens offset by one.
// Set the new presentation display
if (auto xProperties = xPresentation.query<beans::XPropertySet>())
xProperties->setPropertyValue("Display", Any(nNewScreen));
Reference<beans::XPropertySet> xProperties (xPresentation, UNO_QUERY_THROW);
xProperties->setPropertyValue("Display", Any(nNewScreen));
} catch (const uno::Exception &) {
}
}
+2 -2
View File
@@ -799,8 +799,8 @@ Reference<awt::XWindow> PresenterSlideShowView::CreateViewWindow (
xViewWindow.set( xToolkit->createWindow(aWindowDescriptor),UNO_QUERY_THROW);
// Make the background transparent. The slide show paints its own background.
if (auto xPeer = xViewWindow.query<awt::XWindowPeer>())
xPeer->setBackground(0xff000000);
Reference<awt::XWindowPeer> xPeer (xViewWindow, UNO_QUERY_THROW);
xPeer->setBackground(0xff000000);
xViewWindow->setVisible(true);
}
+3 -3
View File
@@ -309,9 +309,9 @@ bool SdStyleSheet::IsUsed() const
Reference< XStyle > xStyle( rListener, UNO_QUERY );
try
{
if (auto xPropertySet = xStyle.query<XPropertySet>() )
if (xPropertySet->getPropertyValue("IsPhysical").get<bool>())
return true;
Reference<XPropertySet> xPropertySet(xStyle, UNO_QUERY_THROW);
if (xPropertySet->getPropertyValue("IsPhysical").get<bool>())
return true;
}
catch (const Exception&)
{
+4 -4
View File
@@ -1944,8 +1944,8 @@ void PPTWriter::ImplWritePage( const PHLayout& rLayout, EscherSolverContainer& a
try
{
// try to get the aspect when available
if (auto xShapeProps = mXShape.query<css::beans::XPropertySet>() )
xShapeProps->getPropertyValue("Aspect") >>= nAspect;
css::uno::Reference< css::beans::XPropertySet > xShapeProps( mXShape, css::uno::UNO_QUERY_THROW );
xShapeProps->getPropertyValue("Aspect") >>= nAspect;
}
catch( css::uno::Exception& )
{}
@@ -2527,8 +2527,8 @@ void PPTWriter::ImplWritePage( const PHLayout& rLayout, EscherSolverContainer& a
try
{
// try to get the aspect when available
if (auto xShapeProps = mXShape.query<css::beans::XPropertySet>() )
xShapeProps->getPropertyValue("Aspect") >>= nAspect;
css::uno::Reference< css::beans::XPropertySet > xShapeProps( mXShape, css::uno::UNO_QUERY_THROW );
xShapeProps->getPropertyValue("Aspect") >>= nAspect;
}
catch( css::uno::Exception& )
{}
+18 -4
View File
@@ -183,15 +183,29 @@ void AnnotationManagerImpl::init()
TOOLS_WARN_EXCEPTION( "sd", "sd::AnnotationManagerImpl::AnnotationManagerImpl()" );
}
if (auto xModel = mrBase.GetDocShell()->GetModel().query<XEventBroadcaster>() )
xModel->addEventListener( Reference<XEventListener>( this ) );
try
{
Reference<XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), UNO_QUERY_THROW );
Reference<XEventListener> xListener( this );
xModel->addEventListener( xListener );
}
catch( Exception& )
{
}
}
// WeakComponentImplHelper
void AnnotationManagerImpl::disposing (std::unique_lock<std::mutex>&)
{
if (auto xModel = mrBase.GetDocShell()->GetModel().query<XEventBroadcaster>() )
xModel->removeEventListener( Reference<XEventListener>( this ) );
try
{
Reference<XEventBroadcaster> xModel (mrBase.GetDocShell()->GetModel(), UNO_QUERY_THROW );
Reference<XEventListener> xListener( this );
xModel->removeEventListener( xListener );
}
catch( Exception& )
{
}
removeListener();
DisposeTags();
+4 -3
View File
@@ -125,9 +125,10 @@ SlideShowView::SlideShowView( ShowWindow& rOutputWindow,
{
try
{
if (auto xCanvasProps = getCanvas().query<beans::XPropertySet>() )
xCanvasProps->setPropertyValue("UnsafeScrolling",
uno::Any( true ) );
Reference< beans::XPropertySet > xCanvasProps( getCanvas(),
uno::UNO_QUERY_THROW );
xCanvasProps->setPropertyValue("UnsafeScrolling",
uno::Any( true ) );
}
catch( uno::Exception& )
{
+8 -10
View File
@@ -73,10 +73,10 @@ static void ImpExtractCustomShow( const Reference< XModel >& rxModel, std::u16st
try
{
PageCollector::CollectNonCustomShowPages( rxModel, rCustomShowName, vNonUsedPageList );
if (auto xDrawPagesSupplier = rxModel.query<XDrawPagesSupplier>() )
if (auto xDrawPages = xDrawPagesSupplier->getDrawPages().query<XDrawPages>() )
for( const auto& rxPage : vNonUsedPageList )
xDrawPages->remove( rxPage );
Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
for( const auto& rxPage : vNonUsedPageList )
xDrawPages->remove( rxPage );
}
catch( Exception& )
{
@@ -544,12 +544,10 @@ static void DispatchURL( const Reference< XComponentContext >& xContext, const O
aUrl.Complete = sURL;
xURLTransformer->parseStrict( aUrl );
Sequence< PropertyValue > aArgs;
if (auto xDispatchProvider = xFrame.query<XDispatchProvider>() )
{
Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aUrl, OUString(), 0 ); // "_self"
if ( xDispatch.is() )
xDispatch->dispatch( aUrl, aArgs );
}
Reference< XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY_THROW );
Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aUrl, OUString(), 0 ); // "_self"
if ( xDispatch.is() )
xDispatch->dispatch( aUrl, aArgs );
}
catch( Exception& )
{
+3 -3
View File
@@ -74,9 +74,9 @@ void OptimizationStats::InitializeStatusValuesFromDocument( const Reference< XMo
{
try
{
if (auto xDrawPagesSupplier = rxModel.query<XDrawPagesSupplier>() )
if (auto xDrawPages = xDrawPagesSupplier->getDrawPages().query<XDrawPages>() )
SetStatusValue( TK_Pages, Any( awt::Size( 0, xDrawPages->getCount() ) ) );
Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
SetStatusValue( TK_Pages, Any( awt::Size( 0, xDrawPages->getCount() ) ) );
}
catch ( Exception& )
{
+5 -2
View File
@@ -1109,8 +1109,11 @@ FileDialogHelper_Impl::FileDialogHelper_Impl(
if ( mbExport )
{
mxFileDlg->setTitle( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) );
if (auto xCtrlAccess = mxFileDlg.query<XFilePickerControlAccess>() )
xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, true );
try {
css::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW );
xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, true );
}
catch( const Exception & ) { }
}
// Save a copy dialog
+2 -2
View File
@@ -1806,8 +1806,8 @@ bool SfxObjectShell_Impl::hasTrustedScriptingSignature( bool bAllowUIToAddAuthor
OUString aVersion;
try
{
if (auto xPropSet = rDocShell.GetStorage().query<beans::XPropertySet>() )
xPropSet->getPropertyValue("Version") >>= aVersion;
uno::Reference < beans::XPropertySet > xPropSet( rDocShell.GetStorage(), uno::UNO_QUERY_THROW );
xPropSet->getPropertyValue("Version") >>= aVersion;
}
catch( uno::Exception& )
{
+42 -24
View File
@@ -1197,8 +1197,8 @@ bool SfxObjectShell::SaveTo_Impl
OUString aODFVersion;
try
{
if (auto xPropSet = GetStorage().query<beans::XPropertySet>() )
xPropSet->getPropertyValue("Version") >>= aODFVersion;
uno::Reference < beans::XPropertySet > xPropSet( GetStorage(), uno::UNO_QUERY_THROW );
xPropSet->getPropertyValue("Version") >>= aODFVersion;
}
catch( uno::Exception& )
{}
@@ -1375,9 +1375,9 @@ bool SfxObjectShell::SaveTo_Impl
try
{
if (auto xProps = rMedium.GetStorage().query<beans::XPropertySet>() )
xProps->setPropertyValue("MediaType",
uno::Any( aDataFlavor.MimeType ) );
uno::Reference< beans::XPropertySet > xProps( rMedium.GetStorage(), uno::UNO_QUERY_THROW );
xProps->setPropertyValue("MediaType",
uno::Any( aDataFlavor.MimeType ) );
}
catch( uno::Exception& )
{
@@ -1591,8 +1591,8 @@ bool SfxObjectShell::SaveTo_Impl
OUString aVersion;
try
{
if (auto xPropSet = rMedium.GetStorage().query<beans::XPropertySet>() )
xPropSet->getPropertyValue("Version") >>= aVersion;
uno::Reference < beans::XPropertySet > xPropSet( rMedium.GetStorage(), uno::UNO_QUERY_THROW );
xPropSet->getPropertyValue("Version") >>= aVersion;
}
catch( uno::Exception& )
{
@@ -1817,16 +1817,14 @@ bool SfxObjectShell::ConnectTmpStorage_Impl(
try
{
// the empty argument means that the storage will create temporary stream itself
if (auto xOptStorage = xStorage.query<embed::XOptimizedStorage>() )
{
xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() );
uno::Reference< embed::XOptimizedStorage > xOptStorage( xStorage, uno::UNO_QUERY_THROW );
xOptStorage->writeAndAttachToStream( uno::Reference< io::XStream >() );
// the storage is successfully disconnected from the original sources, thus the medium must not dispose it
if ( pMediumArg )
pMediumArg->CanDisposeStorage_Impl( false );
// the storage is successfully disconnected from the original sources, thus the medium must not dispose it
if ( pMediumArg )
pMediumArg->CanDisposeStorage_Impl( false );
bResult = true;
}
bResult = true;
}
catch( uno::Exception& )
{
@@ -1851,10 +1849,20 @@ bool SfxObjectShell::ConnectTmpStorage_Impl(
pImpl->aBasicManager.setStorage( xTmpStorage );
// Get rid of this workaround after issue i113914 is fixed
if (auto xBasicLibraries = pImpl->xBasicLibraries.query<script::XStorageBasedLibraryContainer>() )
try
{
uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY_THROW );
xBasicLibraries->setRootStorage( xTmpStorage );
if (auto xDialogLibraries = pImpl->xDialogLibraries.query<script::XStorageBasedLibraryContainer>() )
}
catch( uno::Exception& )
{}
try
{
uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY_THROW );
xDialogLibraries->setRootStorage( xTmpStorage );
}
catch( uno::Exception& )
{}
}
}
catch( uno::Exception& )
@@ -2005,10 +2013,20 @@ bool SfxObjectShell::DoSaveCompleted( SfxMedium* pNewMed, bool bRegisterRecent )
pImpl->aBasicManager.setStorage( xStorage );
// Get rid of this workaround after issue i113914 is fixed
if (auto xBasicLibraries = pImpl->xBasicLibraries.query<script::XStorageBasedLibraryContainer>() )
try
{
uno::Reference< script::XStorageBasedLibraryContainer > xBasicLibraries( pImpl->xBasicLibraries, uno::UNO_QUERY_THROW );
xBasicLibraries->setRootStorage( xStorage );
if (auto xDialogLibraries = pImpl->xDialogLibraries.query<script::XStorageBasedLibraryContainer>() )
}
catch( uno::Exception& )
{}
try
{
uno::Reference< script::XStorageBasedLibraryContainer > xDialogLibraries( pImpl->xDialogLibraries, uno::UNO_QUERY_THROW );
xDialogLibraries->setRootStorage( xStorage );
}
catch( uno::Exception& )
{}
}
else
{
@@ -3432,9 +3450,9 @@ static bool StoragesOfUnknownMediaTypeAreCopied_Impl( const uno::Reference< embe
try
{
if (auto xOptStorage = xSource.query<embed::XOptimizedStorage>() )
bGotMediaType =
( xOptStorage->getElementPropertyValue( rSubElement, aMediaTypePropName ) >>= aMediaType );
uno::Reference< embed::XOptimizedStorage > xOptStorage( xSource, uno::UNO_QUERY_THROW );
bGotMediaType =
( xOptStorage->getElementPropertyValue( rSubElement, aMediaTypePropName ) >>= aMediaType );
}
catch( uno::Exception& )
{}
@@ -3575,8 +3593,8 @@ bool SfxObjectShell::CopyStoragesOfUnknownMediaType(const uno::Reference< embed:
try
{
if (auto xOptStorage = xSource.query<embed::XOptimizedStorage>() )
bGotMediaType = (xOptStorage->getElementPropertyValue(rSubElement, aMediaTypePropName)
uno::Reference< embed::XOptimizedStorage > xOptStorage( xSource, uno::UNO_QUERY_THROW );
bGotMediaType = (xOptStorage->getElementPropertyValue(rSubElement, aMediaTypePropName)
>>= aMediaType);
}
catch( uno::Exception& )
@@ -95,8 +95,13 @@ OLESimpleStorage::OLESimpleStorage(
if ( xInputStream.is() )
{
if (auto xSeek = xInputStream.query<io::XSeekable>() )
try
{
uno::Reference< io::XSeekable > xSeek( xInputStream, uno::UNO_QUERY_THROW );
xSeek->seek( 0 );
}
catch( uno::Exception& )
{}
::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, xTempOut );
xTempOut->closeOutput();
@@ -45,9 +45,9 @@ static bool lcl_isNamedRange( const OUString& sAddress, const uno::Reference< fr
uno::Reference< sheet::XCellRangeReferrer > xReferrer;
try
{
if (auto xPropSet = xModel.query<beans::XPropertySet>() )
if (auto xNamed = xPropSet->getPropertyValue( "NamedRanges" ).query<container::XNameAccess>() )
xReferrer.set ( xNamed->getByName( sAddress ), uno::UNO_QUERY );
uno::Reference< beans::XPropertySet > xPropSet( xModel, uno::UNO_QUERY_THROW );
uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( "NamedRanges" ), uno::UNO_QUERY_THROW );
xReferrer.set ( xNamed->getByName( sAddress ), uno::UNO_QUERY );
}
catch( uno::Exception& /*e*/ )
{
+20 -6
View File
@@ -240,8 +240,13 @@ void SmartTagMgr::WriteConfiguration( const bool* pIsLabelTextWithSmartTags,
if ( bCommit )
{
if (auto xChangesBatch = mxConfigurationSettings.query<util::XChangesBatch>() )
xChangesBatch->commitChanges();
try
{
Reference< util::XChangesBatch >( mxConfigurationSettings, UNO_QUERY_THROW )->commitChanges();
}
catch ( css::uno::Exception& )
{
}
}
}
@@ -443,16 +448,25 @@ void SmartTagMgr::RegisterListener()
{
Reference<deployment::XExtensionManager> xExtensionManager(
deployment::ExtensionManager::get( mxContext ) );
if (auto xMB = xExtensionManager.query<util::XModifyBroadcaster>() )
xMB->addModifyListener( Reference< util::XModifyListener >( this ) );
Reference< util::XModifyBroadcaster > xMB ( xExtensionManager, UNO_QUERY_THROW );
Reference< util::XModifyListener > xListener( this );
xMB->addModifyListener( xListener );
}
catch ( uno::Exception& )
{
}
// register as listener at configuration
if (auto xCN = mxConfigurationSettings.query<util::XChangesNotifier>() )
xCN->addChangesListener( Reference< util::XChangesListener >( this ) );
try
{
Reference<util::XChangesNotifier> xCN( mxConfigurationSettings, UNO_QUERY_THROW );
Reference< util::XChangesListener > xListener( this );
xCN->addChangesListener( xListener );
}
catch ( uno::Exception& )
{
}
}
typedef std::pair < const OUString, ActionReference > SmartTagMapElement;
+7 -1
View File
@@ -2791,8 +2791,14 @@ SvxLineWindow_Impl::SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::W
, m_xLineStyleLbWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xLineStyleLb))
, m_bIsWriter(false)
{
if (auto xServices = m_xFrame->getController()->getModel().query<lang::XServiceInfo>())
try
{
Reference< lang::XServiceInfo > xServices(m_xFrame->getController()->getModel(), UNO_QUERY_THROW);
m_bIsWriter = xServices->supportsService("com.sun.star.text.TextDocument");
}
catch(const uno::Exception& )
{
}
m_xLineStyleLb->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) );
+7 -1
View File
@@ -475,8 +475,14 @@ bool SvxXMLXTableImport::load( const OUString &rPath, const OUString &rReferer,
if (xGraphicHelper.is())
xGraphicStorageHandler = xGraphicHelper.get();
if (auto xSeek = aParserInput.aInputStream.query<io::XSeekable>() )
try
{
uno::Reference< io::XSeekable > xSeek( aParserInput.aInputStream, uno::UNO_QUERY_THROW );
xSeek->seek( 0 );
}
catch (const uno::Exception&)
{
}
rtl::Reference<SvxXMLXTableImport> xImport(new SvxXMLXTableImport(xContext, xTable, xGraphicStorageHandler));
xImport->parseStream( aParserInput );
+4 -6
View File
@@ -623,12 +623,10 @@ void SwOLENode::BreakFileLink_Impl()
try
{
if (auto xLinkSupport = maOLEObj.GetOleRef().query<embed::XLinkageSupport>() )
{
xLinkSupport->breakLink( xStorage, maOLEObj.GetCurrentPersistName() );
DisconnectFileLink_Impl();
maLinkURL.clear();
}
uno::Reference< embed::XLinkageSupport > xLinkSupport( maOLEObj.GetOleRef(), uno::UNO_QUERY_THROW );
xLinkSupport->breakLink( xStorage, maOLEObj.GetCurrentPersistName() );
DisconnectFileLink_Impl();
maLinkURL.clear();
}
catch( uno::Exception& )
{
+3 -5
View File
@@ -295,11 +295,9 @@ ErrCode SwXMLTextBlocks::StartPutBlock( const OUString& rShort, const OUString&
{
m_xRoot = m_xBlkRoot->openStorageElement( rPackageName, embed::ElementModes::READWRITE );
if (auto xRootProps = m_xRoot.query<beans::XPropertySet>() )
{
OUString aMime( SotExchange::GetFormatMimeType( SotClipboardFormatId::STARWRITER_8 ) );
xRootProps->setPropertyValue( "MediaType", uno::Any( aMime ) );
}
uno::Reference< beans::XPropertySet > xRootProps( m_xRoot, uno::UNO_QUERY_THROW );
OUString aMime( SotExchange::GetFormatMimeType( SotClipboardFormatId::STARWRITER_8 ) );
xRootProps->setPropertyValue( "MediaType", uno::Any( aMime ) );
}
catch (const uno::Exception&)
{
+8 -1
View File
@@ -69,8 +69,15 @@ void SwChartHelper::DoUpdateAllCharts( SwDoc* pDoc )
uno::Reference < embed::XEmbeddedObject > xIP = pONd->GetOLEObj().GetOleRef();
if ( svt::EmbeddedObjectRef::TryRunningState( xIP ) )
{
if (auto xModif = xIP->getComponent().query<util::XModifiable>() )
try
{
uno::Reference< util::XModifiable > xModif( xIP->getComponent(), uno::UNO_QUERY_THROW );
xModif->setModified( true );
}
catch ( uno::Exception& )
{
}
}
}
aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
+3 -2
View File
@@ -307,8 +307,9 @@ ErrCode SwXMLWriter::Write_(const SfxItemSet* pMediumItemSet)
&& Version != ODFVER_010_TEXT
&& Version != ODFVER_011_TEXT)
{
if (auto xDMA = xModelComp.query<rdf::XDocumentMetadataAccess>())
xDMA->storeMetadataToStorage(m_xStg);
const uno::Reference<rdf::XDocumentMetadataAccess> xDMA(
xModelComp, uno::UNO_QUERY_THROW);
xDMA->storeMetadataToStorage(m_xStg);
}
}
catch (beans::UnknownPropertyException &)
+8 -1
View File
@@ -167,8 +167,15 @@ namespace
{
void lcl_dispose_nothrow( const Any& i_component )
{
if (auto xComponent = i_component.query<XComponent>() )
try
{
const Reference< XComponent > xComponent( i_component, UNO_QUERY_THROW );
xComponent->dispose();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("toolkit.controls");
}
}
}
@@ -124,8 +124,15 @@ IMPL_STATIC_LINK( MainThreadFrameCloserRequest, worker, void*, p, void )
// ignore all the errors
}
if (auto xCloseable = pMTRequest->m_xFrame.query<util::XCloseable>() )
try
{
uno::Reference< util::XCloseable > xCloseable( pMTRequest->m_xFrame, uno::UNO_QUERY_THROW );
xCloseable->close( true );
}
catch( uno::Exception& )
{
// ignore all the errors
}
}
delete pMTRequest;
+8 -1
View File
@@ -146,8 +146,15 @@ namespace utl
OUString OConfigurationNode::getLocalName() const
{
OUString sLocalName;
if (auto xNamed = m_xDirectAccess.query<XNamed>() )
try
{
Reference< XNamed > xNamed( m_xDirectAccess, UNO_QUERY_THROW );
sLocalName = xNamed->getName();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("unotools");
}
return sLocalName;
}
+3 -5
View File
@@ -1016,11 +1016,9 @@ uno::Sequence< OUString > SvtLinguConfig::GetDisabledDictionaries() const
uno::Sequence< OUString > aResult;
try
{
if (auto xNA = GetMainUpdateAccess().query<container::XNameAccess>() )
{
xNA.set( xNA->getByName("ServiceManager"), uno::UNO_QUERY_THROW );
xNA->getByName( "DisabledDictionaries" ) >>= aResult;
}
uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
xNA.set( xNA->getByName("ServiceManager"), uno::UNO_QUERY_THROW );
xNA->getByName( "DisabledDictionaries" ) >>= aResult;
}
catch (uno::Exception &)
{
+7 -1
View File
@@ -117,8 +117,14 @@ void SvtUserOptions::ChangeListener::changesOccurred (util::ChangesEvent const&
void SvtUserOptions::ChangeListener::disposing (lang::EventObject const& rSource)
{
if (auto xChgNot = rSource.Source.query<util::XChangesNotifier>())
try
{
uno::Reference<util::XChangesNotifier> xChgNot(rSource.Source, uno::UNO_QUERY_THROW);
xChgNot->removeChangesListener(this);
}
catch (uno::Exception&)
{
}
}
SvtUserOptions::Impl::Impl() :
+5 -1
View File
@@ -88,12 +88,16 @@ ScVbaUserForm::Show( )
if ( !mbDispose )
return;
if (auto xComp = m_xDialog.query<lang::XComponent>() )
try
{
uno::Reference< lang::XComponent > xComp( m_xDialog, uno::UNO_QUERY_THROW );
m_xDialog = nullptr;
xComp->dispose();
mbDispose = false;
}
catch( uno::Exception& )
{
}
}
OUString SAL_CALL
@@ -43,10 +43,14 @@ ScVbaColorFormat::ScVbaColorFormat( const uno::Reference< XHelperInterface >& xP
{
m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW );
m_nFillFormatBackColor = 0;
if (auto xFillFormat = xInternalParent.query<ov::msforms::XFillFormat>() )
try
{
uno::Reference< ov::msforms::XFillFormat > xFillFormat( xInternalParent, uno::UNO_QUERY_THROW );
m_pFillFormat = static_cast<ScVbaFillFormat*>( xFillFormat.get() );
else
}catch ( uno::RuntimeException& )
{
m_pFillFormat = nullptr;
}
}
// Attribute
@@ -192,11 +192,16 @@ VbaDocumentBase::Close( const uno::Any &rSaveArg, const uno::Any &rFileArg,
if (bCloseable)
return;
// If close is not supported by this model - try to dispose it.
// But if the model disagree with a reset request for the modify state
// we shouldn't do so. Otherwise some strange things can happen.
if (auto xDisposable = xModel.query<lang::XComponent>() )
try {
// If close is not supported by this model - try to dispose it.
// But if the model disagree with a reset request for the modify state
// we shouldn't do so. Otherwise some strange things can happen.
uno::Reference< lang::XComponent > xDisposable ( xModel, uno::UNO_QUERY_THROW );
xDisposable->dispose();
}
catch(const uno::Exception&)
{
}
}
void
+17 -14
View File
@@ -198,21 +198,24 @@ namespace {
void lclSetupComponent( const uno::Reference< lang::XComponent >& rxComponent, bool bScreenUpdating, bool bInteractive )
{
auto xModel = rxComponent.query<frame::XModel>();
if( !bScreenUpdating && xModel )
xModel->lockControllers();
if( !bScreenUpdating ) try
{
uno::Reference< frame::XModel >( rxComponent, uno::UNO_QUERY_THROW )->lockControllers();
}
catch( uno::Exception& )
{
}
if( !bInteractive )
try
{
if (auto xController = xModel->getCurrentController().query<frame::XController>() )
if (auto xFrame = xController->getFrame().query<frame::XFrame>() )
if (auto xWindow = xFrame->getContainerWindow().query<awt::XWindow>() )
xWindow->setEnable( false );
}
catch( uno::Exception& )
{
}
if( !bInteractive ) try
{
uno::Reference< frame::XModel > xModel( rxComponent, uno::UNO_QUERY_THROW );
uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW );
uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW );
uno::Reference< awt::XWindow >( xFrame->getContainerWindow(), uno::UNO_SET_THROW )->setEnable( false );
}
catch( uno::Exception& )
{
}
}
} // namespace
@@ -4498,12 +4498,16 @@ void DomainMapper_Impl::PopShapeContext()
// or anchored to a discarded header or footer
if ( m_aAnchoredStack.top().bToRemove || m_bDiscardHeaderFooter )
{
if (auto xDrawPageSupplier = m_xTextDocument.query<drawing::XDrawPageSupplier>())
try
{
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(m_xTextDocument, uno::UNO_QUERY_THROW);
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
if ( xDrawPage.is() )
xDrawPage->remove( xShape );
}
catch( const uno::Exception& )
{
}
}
// Relative width calculations deferred until section's margins are defined.
@@ -102,8 +102,14 @@ void ModelEventListener::notifyEvent( const document::EventObject& rEvent )
void ModelEventListener::disposing( const lang::EventObject& rEvent )
{
if (auto xEventBroadcaster = rEvent.Source.query<document::XEventBroadcaster>())
xEventBroadcaster->removeEventListener(uno::Reference<document::XEventListener>(this));
try
{
uno::Reference<document::XEventBroadcaster>(rEvent.Source, uno::UNO_QUERY_THROW )->removeEventListener(
uno::Reference<document::XEventListener>(this));
}
catch( const uno::Exception& )
{
}
}
} //namespace writerfilter::dmapper
+2 -2
View File
@@ -315,8 +315,8 @@ OUString OLEHandler::copyOLEOStream(
sRet = aPersistName.copy( strlen("vnd.sun.star.EmbeddedObject:") );
}
if (auto xComp = xEmbeddedResolver.query<lang::XComponent>() )
xComp->dispose();
uno::Reference< lang::XComponent > xComp( xEmbeddedResolver, uno::UNO_QUERY_THROW );
xComp->dispose();
m_aURL = aURL;
}
catch( const uno::Exception& )
+3 -5
View File
@@ -765,11 +765,9 @@ void SchXMLTableHelper::applyTableToInternalDataProvider(
{
try
{
if (auto xProps = xChartDoc.query<beans::XPropertySet>() )
{
xProps->setPropertyValue( "DisableDataTableDialog", uno::Any( true ) );
xProps->setPropertyValue( "DisableComplexChartTypes", uno::Any( true ) );
}
Reference< beans::XPropertySet > xProps( xChartDoc, uno::UNO_QUERY_THROW );
xProps->setPropertyValue( "DisableDataTableDialog", uno::Any( true ) );
xProps->setPropertyValue( "DisableComplexChartTypes", uno::Any( true ) );
}
catch ( uno::Exception& )
{
@@ -122,8 +122,14 @@ void XMLEmbeddedObjectImportContext::SetComponent( Reference< XComponent > const
SvXMLImport *pFastHandler = dynamic_cast<SvXMLImport*>(xFilter.get());
mxFastHandler = pFastHandler;
if (auto xModifiable2 = rComp.query<XModifiable2>() )
try
{
Reference < XModifiable2 > xModifiable2( rComp, UNO_QUERY_THROW );
xModifiable2->disableSetModified();
}
catch( Exception& )
{
}
Reference < XImporter > xImporter( mxFastHandler, UNO_QUERY );
xImporter->setTargetDocument( rComp );
@@ -236,11 +242,15 @@ void XMLEmbeddedObjectImportContext::endFastElement(sal_Int32 nElement)
mxFastHandler->endFastElement( nElement );
mxFastHandler->endDocument();
if (auto xModifiable2 = xComp.query<XModifiable2>() )
try
{
Reference < XModifiable2 > xModifiable2( xComp, UNO_QUERY_THROW );
xModifiable2->enableSetModified();
xModifiable2->setModified( true ); // trigger new replacement image generation
}
catch( Exception& )
{
}
}
void XMLEmbeddedObjectImportContext::characters( const OUString& rChars )