diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-28 10:33:09 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-29 08:51:48 +0200 |
commit | 1ffba0e356608fb6dbf568248e2a953b4d7fb5d6 (patch) | |
tree | 5da59640441292421f2137bc85ee7291daed137e /framework | |
parent | ce9a41dc387966c74c1af92783a97565b5af3668 (diff) |
loplugin:flatten check for throw in then clause
also make the plugin ignore the case where we have var decl's in the
clause we want to flatten, which could lead to problematic extension of
variable lifetime
Change-Id: I3061f7104e8c6a460bf74f5eac325a516ec50c59
Reviewed-on: https://gerrit.libreoffice.org/42889
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'framework')
7 files changed, 148 insertions, 179 deletions
diff --git a/framework/source/fwe/xml/xmlnamespaces.cxx b/framework/source/fwe/xml/xmlnamespaces.cxx index a505a2101094..9b57861589c2 100644 --- a/framework/source/fwe/xml/xmlnamespaces.cxx +++ b/framework/source/fwe/xml/xmlnamespaces.cxx @@ -70,23 +70,21 @@ void XMLNamespaces::addNamespace( const OUString& aName, const OUString& aValue // for the default namespace - check and throw exception if check fails throw SAXException( "Clearing xml namespace only allowed for default namespace!", Reference< XInterface >(), Any() ); } + + if ( aNamespaceName.isEmpty() ) + m_aDefaultNamespace = aValue; else { - if ( aNamespaceName.isEmpty() ) - m_aDefaultNamespace = aValue; + p = m_aNamespaceMap.find( aNamespaceName ); + if ( p != m_aNamespaceMap.end() ) + { + // replace current namespace definition + m_aNamespaceMap.erase( p ); + m_aNamespaceMap.emplace( aNamespaceName, aValue ); + } else { - p = m_aNamespaceMap.find( aNamespaceName ); - if ( p != m_aNamespaceMap.end() ) - { - // replace current namespace definition - m_aNamespaceMap.erase( p ); - m_aNamespaceMap.emplace( aNamespaceName, aValue ); - } - else - { - m_aNamespaceMap.emplace( aNamespaceName, aValue ); - } + m_aNamespaceMap.emplace( aNamespaceName, aValue ); } } } diff --git a/framework/source/services/substitutepathvars.cxx b/framework/source/services/substitutepathvars.cxx index 7aea555232a6..4d87d98c3e89 100644 --- a/framework/source/services/substitutepathvars.cxx +++ b/framework/source/services/substitutepathvars.cxx @@ -478,8 +478,7 @@ OUString SubstitutePathVariables::impl_substituteVariable( const OUString& rText { throw NoSuchElementException( "Endless recursion detected. Cannot substitute variables!", static_cast<cppu::OWeakObject *>(this) ); } - else - aResult = rText; + aResult = rText; } else { @@ -488,8 +487,7 @@ OUString SubstitutePathVariables::impl_substituteVariable( const OUString& rText { throw NoSuchElementException( "Unknown variable found!", static_cast<cppu::OWeakObject *>(this) ); } - else - aResult = aWorkText; + aResult = aWorkText; } } diff --git a/framework/source/tabwin/tabwindow.cxx b/framework/source/tabwin/tabwindow.cxx index 9070ce850ca8..606f13748517 100644 --- a/framework/source/tabwin/tabwindow.cxx +++ b/framework/source/tabwin/tabwindow.cxx @@ -619,34 +619,32 @@ void SAL_CALL TabWindow::setTabProps( ::sal_Int32 ID, const css::uno::Sequence< sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID )); if ( nPos == TAB_PAGE_NOTFOUND ) throw css::lang::IndexOutOfBoundsException(); - else - { - comphelper::SequenceAsHashMap aSeqHashMap( Properties ); - - OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID )); - sal_Int32 nNewPos = nPos; - aTitle = aSeqHashMap.getUnpackedValueOrDefault< OUString >( - m_aTitlePropName, aTitle ); - pTabControl->SetPageText( sal_uInt16( ID ), aTitle ); - nNewPos = aSeqHashMap.getUnpackedValueOrDefault< sal_Int32 >( - m_aPosPropName, nNewPos ); - if ( nNewPos != sal_Int32( nPos )) - { - nPos = sal_uInt16( nNewPos ); - if ( nPos >= pTabControl->GetPageCount() ) - nPos = TAB_APPEND; + comphelper::SequenceAsHashMap aSeqHashMap( Properties ); - pTabControl->RemovePage( sal_uInt16( ID )); - pTabControl->InsertPage( sal_uInt16( ID ), aTitle, nPos ); - } + OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID )); + sal_Int32 nNewPos = nPos; - /* SAFE AREA ----------------------------------------------------------------------------------------------- */ - aLock.clear(); + aTitle = aSeqHashMap.getUnpackedValueOrDefault< OUString >( + m_aTitlePropName, aTitle ); + pTabControl->SetPageText( sal_uInt16( ID ), aTitle ); + nNewPos = aSeqHashMap.getUnpackedValueOrDefault< sal_Int32 >( + m_aPosPropName, nNewPos ); + if ( nNewPos != sal_Int32( nPos )) + { + nPos = sal_uInt16( nNewPos ); + if ( nPos >= pTabControl->GetPageCount() ) + nPos = TAB_APPEND; - css::uno::Sequence< css::beans::NamedValue > aNamedValueSeq = getTabProps( ID ); - implts_SendNotification( NOTIFY_CHANGED, ID, aNamedValueSeq ); + pTabControl->RemovePage( sal_uInt16( ID )); + pTabControl->InsertPage( sal_uInt16( ID ), aTitle, nPos ); } + + /* SAFE AREA ----------------------------------------------------------------------------------------------- */ + aLock.clear(); + + css::uno::Sequence< css::beans::NamedValue > aNamedValueSeq = getTabProps( ID ); + implts_SendNotification( NOTIFY_CHANGED, ID, aNamedValueSeq ); } } @@ -665,18 +663,16 @@ css::uno::Sequence< css::beans::NamedValue > SAL_CALL TabWindow::getTabProps( :: sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID )); if ( nPos == TAB_PAGE_NOTFOUND ) throw css::lang::IndexOutOfBoundsException(); - else - { - OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID )); - nPos = pTabControl->GetPagePos( sal_uInt16( ID )); - css::uno::Sequence< css::beans::NamedValue > aSeq - { - { m_aTitlePropName, css::uno::makeAny( aTitle ) }, - { m_aPosPropName, css::uno::makeAny( sal_Int32( nPos )) } - }; - return aSeq; - } + OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID )); + nPos = pTabControl->GetPagePos( sal_uInt16( ID )); + + css::uno::Sequence< css::beans::NamedValue > aSeq + { + { m_aTitlePropName, css::uno::makeAny( aTitle ) }, + { m_aPosPropName, css::uno::makeAny( sal_Int32( nPos )) } + }; + return aSeq; } return aNamedValueSeq; @@ -696,21 +692,19 @@ void SAL_CALL TabWindow::activateTab( ::sal_Int32 ID ) sal_uInt16 nPos = pTabControl->GetPagePos( sal_uInt16( ID )); if ( nPos == TAB_PAGE_NOTFOUND ) throw css::lang::IndexOutOfBoundsException(); - else - { - sal_Int32 nOldID = pTabControl->GetCurPageId(); - OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID )); - pTabControl->SetCurPageId( sal_uInt16( ID )); - pTabControl->SelectTabPage( sal_uInt16( ID )); - impl_SetTitle( aTitle ); - - aLock.clear(); - /* SAFE AREA ----------------------------------------------------------------------------------------------- */ - - if ( nOldID != TAB_PAGE_NOTFOUND ) - implts_SendNotification( NOTIFY_DEACTIVATED, nOldID ); - implts_SendNotification( NOTIFY_ACTIVATED, ID ); - } + + sal_Int32 nOldID = pTabControl->GetCurPageId(); + OUString aTitle = pTabControl->GetPageText( sal_uInt16( ID )); + pTabControl->SetCurPageId( sal_uInt16( ID )); + pTabControl->SelectTabPage( sal_uInt16( ID )); + impl_SetTitle( aTitle ); + + aLock.clear(); + /* SAFE AREA ----------------------------------------------------------------------------------------------- */ + + if ( nOldID != TAB_PAGE_NOTFOUND ) + implts_SendNotification( NOTIFY_DEACTIVATED, nOldID ); + implts_SendNotification( NOTIFY_ACTIVATED, ID ); } } diff --git a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx index 403e045c99f8..fcde32765a42 100644 --- a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx +++ b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx @@ -1128,17 +1128,15 @@ sal_Bool SAL_CALL ModuleUIConfigurationManager::hasSettings( const OUString& Res if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); - if ( pDataSettings ) - return true; - } + if ( m_bDisposed ) + throw DisposedException(); + + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); + if ( pDataSettings ) + return true; return false; } @@ -1150,22 +1148,20 @@ Reference< XIndexAccess > SAL_CALL ModuleUIConfigurationManager::getSettings( co if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); - if ( pDataSettings ) - { - // Create a copy of our data if someone wants to change the data. - if ( bWriteable ) - return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); - else - return pDataSettings->xSettings; - } + if ( m_bDisposed ) + throw DisposedException(); + + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); + if ( pDataSettings ) + { + // Create a copy of our data if someone wants to change the data. + if ( bWriteable ) + return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); + else + return pDataSettings->xSettings; } throw NoSuchElementException(); @@ -1474,17 +1470,15 @@ sal_Bool SAL_CALL ModuleUIConfigurationManager::isDefaultSettings( const OUStrin if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); - if ( pDataSettings && pDataSettings->bDefaultNode ) - return true; - } + if ( m_bDisposed ) + throw DisposedException(); + + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); + if ( pDataSettings && pDataSettings->bDefaultNode ) + return true; return false; } @@ -1496,25 +1490,23 @@ Reference< XIndexAccess > SAL_CALL ModuleUIConfigurationManager::getDefaultSetti if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - // preload list of element types on demand - impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType ); + if ( m_bDisposed ) + throw DisposedException(); - // Look into our default vector/unordered_map combination - UIElementDataHashMap& rDefaultHashMap = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap; - UIElementDataHashMap::iterator pIter = rDefaultHashMap.find( ResourceURL ); - if ( pIter != rDefaultHashMap.end() ) - { - if ( !pIter->second.xSettings.is() ) - impl_requestUIElementData( nElementType, LAYER_DEFAULT, pIter->second ); - return pIter->second.xSettings; - } + // preload list of element types on demand + impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType ); + + // Look into our default vector/unordered_map combination + UIElementDataHashMap& rDefaultHashMap = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap; + UIElementDataHashMap::iterator pIter = rDefaultHashMap.find( ResourceURL ); + if ( pIter != rDefaultHashMap.end() ) + { + if ( !pIter->second.xSettings.is() ) + impl_requestUIElementData( nElementType, LAYER_DEFAULT, pIter->second ); + return pIter->second.xSettings; } // Nothing has been found! diff --git a/framework/source/uiconfiguration/uiconfigurationmanager.cxx b/framework/source/uiconfiguration/uiconfigurationmanager.cxx index 06b267a48700..16a3ca5310cf 100644 --- a/framework/source/uiconfiguration/uiconfigurationmanager.cxx +++ b/framework/source/uiconfiguration/uiconfigurationmanager.cxx @@ -902,12 +902,9 @@ sal_Bool SAL_CALL UIConfigurationManager::hasSettings( const OUString& ResourceU if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); - if ( pDataSettings && !pDataSettings->bDefault ) - return true; - } + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); + if ( pDataSettings && !pDataSettings->bDefault ) + return true; return false; } @@ -919,22 +916,20 @@ Reference< XIndexAccess > SAL_CALL UIConfigurationManager::getSettings( const OU if (( nElementType == css::ui::UIElementType::UNKNOWN ) || ( nElementType >= css::ui::UIElementType::COUNT )) throw IllegalArgumentException(); - else - { - SolarMutexGuard g; - if ( m_bDisposed ) - throw DisposedException(); + SolarMutexGuard g; - UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); - if ( pDataSettings && !pDataSettings->bDefault ) - { - // Create a copy of our data if someone wants to change the data. - if ( bWriteable ) - return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); - else - return pDataSettings->xSettings; - } + if ( m_bDisposed ) + throw DisposedException(); + + UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); + if ( pDataSettings && !pDataSettings->bDefault ) + { + // Create a copy of our data if someone wants to change the data. + if ( bWriteable ) + return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); + else + return pDataSettings->xSettings; } throw NoSuchElementException(); diff --git a/framework/source/uiconfiguration/windowstateconfiguration.cxx b/framework/source/uiconfiguration/windowstateconfiguration.cxx index 97c71e7a39b4..99a6464c50e0 100644 --- a/framework/source/uiconfiguration/windowstateconfiguration.cxx +++ b/framework/source/uiconfiguration/windowstateconfiguration.cxx @@ -255,8 +255,7 @@ Any SAL_CALL ConfigurationAccess_WindowState::getByName( const OUString& rResour Any a( impl_getWindowStateFromResourceURL( rResourceURL ) ); if ( a == Any() ) throw NoSuchElementException(); - else - return a; + return a; } } @@ -365,54 +364,49 @@ void SAL_CALL ConfigurationAccess_WindowState::insertByName( const OUString& rRe ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL ); if ( pIter != m_aResourceURLToInfoCache.end() ) throw ElementExistException(); - else + + if ( !m_bConfigAccessInitialized ) { - if ( !m_bConfigAccessInitialized ) - { - impl_initializeConfigAccess(); - m_bConfigAccessInitialized = true; - } + impl_initializeConfigAccess(); + m_bConfigAccessInitialized = true; + } - // Try to ask our configuration access - if ( m_xConfigAccess.is() ) + // Try to ask our configuration access + if ( m_xConfigAccess.is() ) + { + if ( m_xConfigAccess->hasByName( rResourceURL ) ) + throw ElementExistException(); + + WindowStateInfo aWinStateInfo; + impl_fillStructFromSequence( aWinStateInfo, aPropSet ); + m_aResourceURLToInfoCache.emplace( rResourceURL, aWinStateInfo ); + + // insert must be write-through => insert element into configuration + Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY ); + if ( xNameContainer.is() ) { - if ( m_xConfigAccess->hasByName( rResourceURL ) ) - throw ElementExistException(); - else - { - WindowStateInfo aWinStateInfo; - impl_fillStructFromSequence( aWinStateInfo, aPropSet ); - m_aResourceURLToInfoCache.emplace( rResourceURL, aWinStateInfo ); + Reference< XSingleServiceFactory > xFactory( m_xConfigAccess, UNO_QUERY ); + g.clear(); - // insert must be write-through => insert element into configuration - Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY ); - if ( xNameContainer.is() ) + try + { + Reference< XPropertySet > xPropSet( xFactory->createInstance(), UNO_QUERY ); + if ( xPropSet.is() ) { - Reference< XSingleServiceFactory > xFactory( m_xConfigAccess, UNO_QUERY ); - g.clear(); - - try - { - Reference< XPropertySet > xPropSet( xFactory->createInstance(), UNO_QUERY ); - if ( xPropSet.is() ) - { - Any a; - impl_putPropertiesFromStruct( aWinStateInfo, xPropSet ); - a <<= xPropSet; - xNameContainer->insertByName( rResourceURL, a ); - Reference< XChangesBatch > xFlush( xFactory, UNO_QUERY ); - if ( xFlush.is() ) - xFlush->commitChanges(); - } - } - catch ( const Exception& ) - { - } + Any a; + impl_putPropertiesFromStruct( aWinStateInfo, xPropSet ); + a <<= xPropSet; + xNameContainer->insertByName( rResourceURL, a ); + Reference< XChangesBatch > xFlush( xFactory, UNO_QUERY ); + if ( xFlush.is() ) + xFlush->commitChanges(); } } + catch ( const Exception& ) + { + } } } - } // XNameReplace diff --git a/framework/source/uifactory/uielementfactorymanager.cxx b/framework/source/uifactory/uielementfactorymanager.cxx index 557a38c7d665..a3b33637ca8a 100644 --- a/framework/source/uifactory/uielementfactorymanager.cxx +++ b/framework/source/uifactory/uielementfactorymanager.cxx @@ -128,8 +128,7 @@ void ConfigurationAccess_FactoryManager::addFactorySpecifierToTypeNameModule( co if ( pIter != m_aFactoryManagerMap.end() ) throw ElementExistException(); - else - m_aFactoryManagerMap.emplace( aHashKey, rServiceSpecifier ); + m_aFactoryManagerMap.emplace( aHashKey, rServiceSpecifier ); } void ConfigurationAccess_FactoryManager::removeFactorySpecifierFromTypeNameModule( const OUString& rType, const OUString& rName, const OUString& rModule ) @@ -143,8 +142,7 @@ void ConfigurationAccess_FactoryManager::removeFactorySpecifierFromTypeNameModul if ( pIter == m_aFactoryManagerMap.end() ) throw NoSuchElementException(); - else - m_aFactoryManagerMap.erase( aHashKey ); + m_aFactoryManagerMap.erase( aHashKey ); } Sequence< Sequence< PropertyValue > > ConfigurationAccess_FactoryManager::getFactoriesDescription() const |