diff options
-rw-r--r-- | comphelper/source/property/propagg.cxx | 148 | ||||
-rw-r--r-- | compilerplugins/clang/test/unnecessarycatchthrow.cxx | 35 | ||||
-rw-r--r-- | compilerplugins/clang/unnecessarycatchthrow.cxx | 79 | ||||
-rw-r--r-- | dbaccess/source/core/api/tablecontainer.cxx | 86 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/linkeddocuments.cxx | 20 | ||||
-rw-r--r-- | filter/source/config/cache/filtercache.cxx | 20 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolder.cxx | 16 | ||||
-rw-r--r-- | reportdesign/source/core/api/ReportDefinition.cxx | 62 | ||||
-rw-r--r-- | reportdesign/source/core/api/ReportEngineJFree.cxx | 172 | ||||
-rw-r--r-- | sd/source/ui/presenter/PresenterTextView.cxx | 15 | ||||
-rw-r--r-- | sd/source/ui/slidesorter/shell/SlideSorterService.cxx | 48 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 16 | ||||
-rw-r--r-- | solenv/CompilerTest_compilerplugins_clang.mk | 1 | ||||
-rw-r--r-- | ucb/source/cacher/cachedcontentresultset.cxx | 13 |
14 files changed, 379 insertions, 352 deletions
diff --git a/comphelper/source/property/propagg.cxx b/comphelper/source/property/propagg.cxx index 43f461921fac..dd97cee7f4fe 100644 --- a/comphelper/source/property/propagg.cxx +++ b/comphelper/source/property/propagg.cxx @@ -638,109 +638,101 @@ void SAL_CALL OPropertySetAggregationHelper::setPropertyValues( { const css::uno::Any* pValues = _rValues.getConstArray(); - try - { - // dividing the Names and _rValues + // dividing the Names and _rValues - // aggregate's names - Sequence< OUString > AggPropertyNames( nAggCount ); - OUString* pAggNames = AggPropertyNames.getArray(); - // aggregate's values - Sequence< Any > AggValues( nAggCount ); - Any* pAggValues = AggValues.getArray(); + // aggregate's names + Sequence< OUString > AggPropertyNames( nAggCount ); + OUString* pAggNames = AggPropertyNames.getArray(); + // aggregate's values + Sequence< Any > AggValues( nAggCount ); + Any* pAggValues = AggValues.getArray(); - // delegator names - Sequence< OUString > DelPropertyNames( nLen - nAggCount ); - OUString* pDelNames = DelPropertyNames.getArray(); + // delegator names + Sequence< OUString > DelPropertyNames( nLen - nAggCount ); + OUString* pDelNames = DelPropertyNames.getArray(); - // delegator values - Sequence< Any > DelValues( nLen - nAggCount ); - Any* pDelValues = DelValues.getArray(); + // delegator values + Sequence< Any > DelValues( nLen - nAggCount ); + Any* pDelValues = DelValues.getArray(); - for ( sal_Int32 i = 0; i < nLen; ++i, ++pNames, ++pValues ) + for ( sal_Int32 i = 0; i < nLen; ++i, ++pNames, ++pValues ) + { + if ( OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate == rPH.classifyProperty( *pNames ) ) { - if ( OPropertyArrayAggregationHelper::PropertyOrigin::Aggregate == rPH.classifyProperty( *pNames ) ) - { - *pAggNames++ = *pNames; - *pAggValues++ = *pValues; - } - else - { - *pDelNames++ = *pNames; - *pDelValues++ = *pValues; - } + *pAggNames++ = *pNames; + *pAggValues++ = *pValues; } + else + { + *pDelNames++ = *pNames; + *pDelValues++ = *pValues; + } + } - // reset, needed below - pDelValues = DelValues.getArray(); + // reset, needed below + pDelValues = DelValues.getArray(); - std::unique_ptr<sal_Int32[]> pHandles(new sal_Int32[ nLen - nAggCount ]); + std::unique_ptr<sal_Int32[]> pHandles(new sal_Int32[ nLen - nAggCount ]); - // get the map table - cppu::IPropertyArrayHelper& rPH2 = getInfoHelper(); + // get the map table + cppu::IPropertyArrayHelper& rPH2 = getInfoHelper(); - // fill the handle array - sal_Int32 nHitCount = rPH2.fillHandles( pHandles.get(), DelPropertyNames ); - if (nHitCount != 0) - { - std::unique_ptr< css::uno::Any[]> pConvertedValues(new css::uno::Any[ nHitCount ]); - std::unique_ptr< css::uno::Any[]> pOldValues(new css::uno::Any[ nHitCount ]); - nHitCount = 0; - sal_Int32 i; + // fill the handle array + sal_Int32 nHitCount = rPH2.fillHandles( pHandles.get(), DelPropertyNames ); + if (nHitCount != 0) + { + std::unique_ptr< css::uno::Any[]> pConvertedValues(new css::uno::Any[ nHitCount ]); + std::unique_ptr< css::uno::Any[]> pOldValues(new css::uno::Any[ nHitCount ]); + nHitCount = 0; + sal_Int32 i; + { + // must lock the mutex outside the loop. So all values are consistent. + osl::MutexGuard aGuard( rBHelper.rMutex ); + for( i = 0; i < (nLen - nAggCount); ++i ) { - // must lock the mutex outside the loop. So all values are consistent. - osl::MutexGuard aGuard( rBHelper.rMutex ); - for( i = 0; i < (nLen - nAggCount); ++i ) + if( pHandles[i] != -1 ) { - if( pHandles[i] != -1 ) + sal_Int16 nAttributes; + rPH2.fillPropertyMembersByHandle( nullptr, &nAttributes, pHandles[i] ); + if( nAttributes & css::beans::PropertyAttribute::READONLY ) + throw css::beans::PropertyVetoException(); + // Will the property change? + if( convertFastPropertyValue( pConvertedValues[ nHitCount ], pOldValues[nHitCount], + pHandles[i], pDelValues[i] ) ) { - sal_Int16 nAttributes; - rPH2.fillPropertyMembersByHandle( nullptr, &nAttributes, pHandles[i] ); - if( nAttributes & css::beans::PropertyAttribute::READONLY ) - throw css::beans::PropertyVetoException(); - // Will the property change? - if( convertFastPropertyValue( pConvertedValues[ nHitCount ], pOldValues[nHitCount], - pHandles[i], pDelValues[i] ) ) - { - // only increment if the property really change - pHandles[nHitCount] = pHandles[i]; - nHitCount++; - } + // only increment if the property really change + pHandles[nHitCount] = pHandles[i]; + nHitCount++; } } - // release guard to fire events } + // release guard to fire events + } - // fire vetoable events - fire( pHandles.get(), pConvertedValues.get(), pOldValues.get(), nHitCount, true ); + // fire vetoable events + fire( pHandles.get(), pConvertedValues.get(), pOldValues.get(), nHitCount, true ); - // setting the agg Properties - m_xAggregateMultiSet->setPropertyValues(AggPropertyNames, AggValues); + // setting the agg Properties + m_xAggregateMultiSet->setPropertyValues(AggPropertyNames, AggValues); + { + // must lock the mutex outside the loop. + osl::MutexGuard aGuard( rBHelper.rMutex ); + // Loop over all changed properties + for( i = 0; i < nHitCount; i++ ) { - // must lock the mutex outside the loop. - osl::MutexGuard aGuard( rBHelper.rMutex ); - // Loop over all changed properties - for( i = 0; i < nHitCount; i++ ) - { - // Will the property change? - setFastPropertyValue_NoBroadcast( pHandles[i], pConvertedValues[i] ); - } - // release guard to fire events + // Will the property change? + setFastPropertyValue_NoBroadcast( pHandles[i], pConvertedValues[i] ); } - - // fire change events - fire( pHandles.get(), pConvertedValues.get(), pOldValues.get(), nHitCount, false ); + // release guard to fire events } - else - m_xAggregateMultiSet->setPropertyValues(AggPropertyNames, AggValues); + // fire change events + fire( pHandles.get(), pConvertedValues.get(), pOldValues.get(), nHitCount, false ); } - catch(css::uno::Exception&) - { - throw; - } + else + m_xAggregateMultiSet->setPropertyValues(AggPropertyNames, AggValues); } } } diff --git a/compilerplugins/clang/test/unnecessarycatchthrow.cxx b/compilerplugins/clang/test/unnecessarycatchthrow.cxx new file mode 100644 index 000000000000..5fb8d83bf9a6 --- /dev/null +++ b/compilerplugins/clang/test/unnecessarycatchthrow.cxx @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <iostream> +#include <fstream> + +void foo(); + +int main() +{ + try { + foo(); + } catch(int const &) { // expected-error {{unnecessary catch and throw [loplugin:unnecessarycatchthrow]}} + throw; + } + try { + foo(); + } catch(int const & ex) { // expected-error {{unnecessary catch and throw [loplugin:unnecessarycatchthrow]}} + throw ex; + } + try { + foo(); + } catch(int const &) { + std::cout << "test"; + throw; + } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/unnecessarycatchthrow.cxx b/compilerplugins/clang/unnecessarycatchthrow.cxx new file mode 100644 index 000000000000..c69713799a82 --- /dev/null +++ b/compilerplugins/clang/unnecessarycatchthrow.cxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <cassert> +#include <string> +#include <iostream> +#include <fstream> +#include <set> + +#include <clang/AST/CXXInheritance.h> +#include "compat.hxx" +#include "plugin.hxx" + +/** +look for unnecessary blocks that just catch and rethrow: + try { + stuff + } catch (exception const &) { + throw; + } +*/ + +namespace { + +class UnnecessaryCatchThrow: + public RecursiveASTVisitor<UnnecessaryCatchThrow>, public loplugin::Plugin +{ +public: + explicit UnnecessaryCatchThrow(InstantiationData const & data): Plugin(data) {} + + virtual void run() override + { + TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); + } + + bool VisitCXXTryStmt(CXXTryStmt const *); +}; + +bool UnnecessaryCatchThrow::VisitCXXTryStmt(CXXTryStmt const * tryStmt) +{ + if (ignoreLocation(tryStmt)) + return true; + if (tryStmt->getNumHandlers() != 1) + return true; + auto catchStmt = tryStmt->getHandler(0); + auto compoundStmt = dyn_cast<CompoundStmt>(catchStmt->getHandlerBlock()); + if (!compoundStmt || compoundStmt->size() != 1) + return true; + auto throwExpr = dyn_cast<CXXThrowExpr>(compoundStmt->body_front()); + if (!throwExpr) + return true; + auto subExpr = throwExpr->getSubExpr(); + if (subExpr) + { + auto declRefExpr = dyn_cast<DeclRefExpr>(subExpr->IgnoreImpCasts()); + if (!declRefExpr) + return true; + if (declRefExpr->getDecl() != catchStmt->getExceptionDecl()) + return true; + } + + report( DiagnosticsEngine::Warning, "unnecessary catch and throw", + catchStmt->getLocStart()) + << catchStmt->getSourceRange(); + return true; +} + + +loplugin::Plugin::Registration< UnnecessaryCatchThrow > X("unnecessarycatchthrow"); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/core/api/tablecontainer.cxx b/dbaccess/source/core/api/tablecontainer.cxx index c900a5e4ec0e..a7ce9d8981e2 100644 --- a/dbaccess/source/core/api/tablecontainer.cxx +++ b/dbaccess/source/core/api/tablecontainer.cxx @@ -271,7 +271,6 @@ ObjectType OTableContainer::appendObject( const OUString& _rForName, const Refer PContainerApprove pApprove( new ObjectNameApproval( xConnection, ObjectNameApproval::TypeTable ) ); pApprove->approveElement( aName, descriptor ); - try { EnsureReset aReset(m_nInAppend); Reference<XAppend> xAppend(m_xMasterContainer,UNO_QUERY); @@ -294,10 +293,6 @@ ObjectType OTableContainer::appendObject( const OUString& _rForName, const Refer } } } - catch(const Exception&) - { - throw; - } Reference<XPropertySet> xTableDefinition; Reference<XNameAccess> xColumnDefinitions; @@ -343,61 +338,54 @@ ObjectType OTableContainer::appendObject( const OUString& _rForName, const Refer // XDrop void OTableContainer::dropObject(sal_Int32 _nPos, const OUString& _sElementName) { - try + Reference< XDrop > xDrop(m_xMasterContainer,UNO_QUERY); + if(xDrop.is()) + xDrop->dropByName(_sElementName); + else { - Reference< XDrop > xDrop(m_xMasterContainer,UNO_QUERY); - if(xDrop.is()) - xDrop->dropByName(_sElementName); - else - { - OUString sCatalog,sSchema,sTable,sComposedName; + OUString sCatalog,sSchema,sTable,sComposedName; - bool bIsView = false; - Reference<XPropertySet> xTable(getObject(_nPos),UNO_QUERY); - if ( xTable.is() && m_xMetaData.is() ) - { - if( m_xMetaData.is() && m_xMetaData->supportsCatalogsInTableDefinitions() ) - xTable->getPropertyValue(PROPERTY_CATALOGNAME) >>= sCatalog; - if( m_xMetaData.is() && m_xMetaData->supportsSchemasInTableDefinitions() ) - xTable->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema; - xTable->getPropertyValue(PROPERTY_NAME) >>= sTable; + bool bIsView = false; + Reference<XPropertySet> xTable(getObject(_nPos),UNO_QUERY); + if ( xTable.is() && m_xMetaData.is() ) + { + if( m_xMetaData.is() && m_xMetaData->supportsCatalogsInTableDefinitions() ) + xTable->getPropertyValue(PROPERTY_CATALOGNAME) >>= sCatalog; + if( m_xMetaData.is() && m_xMetaData->supportsSchemasInTableDefinitions() ) + xTable->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema; + xTable->getPropertyValue(PROPERTY_NAME) >>= sTable; - sComposedName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, true, ::dbtools::EComposeRule::InTableDefinitions ); + sComposedName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, true, ::dbtools::EComposeRule::InTableDefinitions ); - OUString sType; - xTable->getPropertyValue(PROPERTY_TYPE) >>= sType; - bIsView = sType.equalsIgnoreAsciiCase("VIEW"); - } + OUString sType; + xTable->getPropertyValue(PROPERTY_TYPE) >>= sType; + bIsView = sType.equalsIgnoreAsciiCase("VIEW"); + } - if(sComposedName.isEmpty()) - ::dbtools::throwFunctionSequenceException(static_cast<XTypeProvider*>(static_cast<OFilteredContainer*>(this))); + if(sComposedName.isEmpty()) + ::dbtools::throwFunctionSequenceException(static_cast<XTypeProvider*>(static_cast<OFilteredContainer*>(this))); - OUString aSql("DROP "); + OUString aSql("DROP "); - if ( bIsView ) // here we have a view - aSql += "VIEW "; - else - aSql += "TABLE "; - aSql += sComposedName; - Reference<XConnection> xCon = m_xConnection; - OSL_ENSURE(xCon.is(),"Connection is null!"); - if ( xCon.is() ) - { - Reference< XStatement > xStmt = xCon->createStatement( ); - if(xStmt.is()) - xStmt->execute(aSql); - ::comphelper::disposeComponent(xStmt); - } - } - - if ( m_xTableDefinitions.is() && m_xTableDefinitions->hasByName(_sElementName) ) + if ( bIsView ) // here we have a view + aSql += "VIEW "; + else + aSql += "TABLE "; + aSql += sComposedName; + Reference<XConnection> xCon = m_xConnection; + OSL_ENSURE(xCon.is(),"Connection is null!"); + if ( xCon.is() ) { - m_xTableDefinitions->removeByName(_sElementName); + Reference< XStatement > xStmt = xCon->createStatement( ); + if(xStmt.is()) + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); } } - catch(const Exception&) + + if ( m_xTableDefinitions.is() && m_xTableDefinitions->hasByName(_sElementName) ) { - throw; + m_xTableDefinitions->removeByName(_sElementName); } } diff --git a/dbaccess/source/ui/misc/linkeddocuments.cxx b/dbaccess/source/ui/misc/linkeddocuments.cxx index d4e41b2e5385..102f7eca51a6 100644 --- a/dbaccess/source/ui/misc/linkeddocuments.cxx +++ b/dbaccess/source/ui/misc/linkeddocuments.cxx @@ -151,23 +151,17 @@ namespace dbaui aArguments.put( "OpenMode", sOpenMode ); aArguments.put( OUString(PROPERTY_ACTIVE_CONNECTION), m_xConnection ); - try - { - Reference<XHierarchicalNameContainer> xHier(m_xDocumentContainer,UNO_QUERY); - if ( xHier.is() && xHier->hasByHierarchicalName(_rLinkName) ) - { - _xDefinition.set(xHier->getByHierarchicalName(_rLinkName),UNO_QUERY); - } - - aArguments.merge( _rAdditionalArgs, true ); - xRet = xComponentLoader->loadComponentFromURL( _rLinkName, OUString(), 0, aArguments.getPropertyValues() ); - } - catch(const Exception&) + Reference<XHierarchicalNameContainer> xHier(m_xDocumentContainer,UNO_QUERY); + if ( xHier.is() && xHier->hasByHierarchicalName(_rLinkName) ) { - throw; + _xDefinition.set(xHier->getByHierarchicalName(_rLinkName),UNO_QUERY); } + aArguments.merge( _rAdditionalArgs, true ); + + xRet = xComponentLoader->loadComponentFromURL( _rLinkName, OUString(), 0, aArguments.getPropertyValues() ); + return xRet; } void OLinkedDocumentsAccess::impl_newWithPilot( const char* _pWizardService, diff --git a/filter/source/config/cache/filtercache.cxx b/filter/source/config/cache/filtercache.cxx index bb4c95b3c95a..423a35c2e955 100644 --- a/filter/source/config/cache/filtercache.cxx +++ b/filter/source/config/cache/filtercache.cxx @@ -25,7 +25,6 @@ /*TODO see using below ... */ #define AS_ENABLE_FILTER_UINAMES -#define WORKAROUND_EXCEPTION_PROBLEM #include <com/sun/star/configuration/theDefaultProvider.hpp> #include <com/sun/star/util/XChangesBatch.hpp> @@ -1573,23 +1572,12 @@ CacheItem FilterCache::impl_loadItem(const css::uno::Reference< css::container:: // break this operation. Of course returned API object must be // checked too. css::uno::Reference< css::container::XNameAccess > xItem; - #ifdef WORKAROUND_EXCEPTION_PROBLEM - try - { - #endif - css::uno::Any aVal = xSet->getByName(sItem); - if (!(aVal >>= xItem) || !xItem.is()) - { - OUString sMsg("found corrupted item \"" + sItem + "\"."); - throw css::uno::RuntimeException(sMsg, css::uno::Reference< css::uno::XInterface >()); - } - #ifdef WORKAROUND_EXCEPTION_PROBLEM - } - catch(const css::container::NoSuchElementException&) + css::uno::Any aVal = xSet->getByName(sItem); + if (!(aVal >>= xItem) || !xItem.is()) { - throw; + throw css::uno::RuntimeException("found corrupted item \"" + sItem + "\".", + css::uno::Reference< css::uno::XInterface >()); } - #endif // set too. Of course its already used as key into the e.g. outside // used hash map ... but some of our API methods provide diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index 5d75838cfd3c..ed5e6d0d29ed 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -407,20 +407,14 @@ uno::Any SAL_CALL ZipPackageFolder::getPropertyValue( const OUString& PropertyNa void ZipPackageFolder::doInsertByName ( ZipPackageEntry *pEntry, bool bSetParent ) { - try - { - if ( pEntry->IsFolder() ) - maContents[pEntry->getName()] = o3tl::make_unique<ZipContentInfo>(static_cast<ZipPackageFolder*>(pEntry)); - else - maContents[pEntry->getName()] = o3tl::make_unique<ZipContentInfo>(static_cast<ZipPackageStream*>(pEntry)); - } - catch(const uno::Exception&) - { - throw; - } + if ( pEntry->IsFolder() ) + maContents[pEntry->getName()] = o3tl::make_unique<ZipContentInfo>(static_cast<ZipPackageFolder*>(pEntry)); + else + maContents[pEntry->getName()] = o3tl::make_unique<ZipContentInfo>(static_cast<ZipPackageStream*>(pEntry)); if ( bSetParent ) pEntry->setParent ( *this ); } + OUString ZipPackageFolder::getImplementationName() { return OUString("ZipPackageFolder"); diff --git a/reportdesign/source/core/api/ReportDefinition.cxx b/reportdesign/source/core/api/ReportDefinition.cxx index ca6d941dcf50..a2a746474283 100644 --- a/reportdesign/source/core/api/ReportDefinition.cxx +++ b/reportdesign/source/core/api/ReportDefinition.cxx @@ -1484,46 +1484,40 @@ bool OReportDefinition::WriteThroughComponent( { OSL_ENSURE( nullptr != pStreamName, "Need stream name!" ); OSL_ENSURE( nullptr != pServiceName, "Need service name!" ); - try + + // open stream + OUString sStreamName = OUString::createFromAscii( pStreamName ); + uno::Reference<io::XStream> xStream = _xStorageToSaveTo->openStreamElement( sStreamName,embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); + if ( !xStream.is() ) + return false; + uno::Reference<io::XOutputStream> xOutputStream = xStream->getOutputStream(); + OSL_ENSURE(xOutputStream.is(), "Can't create output stream in package!"); + if ( ! xOutputStream.is() ) + return false; + + uno::Reference<beans::XPropertySet> xStreamProp(xOutputStream,uno::UNO_QUERY); + OSL_ENSURE(xStreamProp.is(),"No valid property set for the output stream!"); + + uno::Reference<io::XSeekable> xSeek(xStreamProp,uno::UNO_QUERY); + if ( xSeek.is() ) { - // open stream - OUString sStreamName = OUString::createFromAscii( pStreamName ); - uno::Reference<io::XStream> xStream = _xStorageToSaveTo->openStreamElement( sStreamName,embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - if ( !xStream.is() ) - return false; - uno::Reference<io::XOutputStream> xOutputStream = xStream->getOutputStream(); - OSL_ENSURE(xOutputStream.is(), "Can't create output stream in package!"); - if ( ! xOutputStream.is() ) - return false; - - uno::Reference<beans::XPropertySet> xStreamProp(xOutputStream,uno::UNO_QUERY); - OSL_ENSURE(xStreamProp.is(),"No valid property set for the output stream!"); - - uno::Reference<io::XSeekable> xSeek(xStreamProp,uno::UNO_QUERY); - if ( xSeek.is() ) - { - xSeek->seek(0); - } + xSeek->seek(0); + } - xStreamProp->setPropertyValue( "MediaType", uno::Any(OUString("text/xml")) ); + xStreamProp->setPropertyValue( "MediaType", uno::Any(OUString("text/xml")) ); - // encrypt all streams - xStreamProp->setPropertyValue( "UseCommonStoragePasswordEncryption", + // encrypt all streams + xStreamProp->setPropertyValue( "UseCommonStoragePasswordEncryption", uno::makeAny( true ) ); - // set buffer and create outputstream + // set buffer and create outputstream - // write the stuff - bool bRet = WriteThroughComponent( - xOutputStream, xComponent, - pServiceName, rArguments, rMediaDesc ); - // finally, commit stream. - return bRet; - } - catch (const uno::Exception&) - { - throw; - } + // write the stuff + bool bRet = WriteThroughComponent( + xOutputStream, xComponent, + pServiceName, rArguments, rMediaDesc ); + // finally, commit stream. + return bRet; } bool OReportDefinition::WriteThroughComponent( diff --git a/reportdesign/source/core/api/ReportEngineJFree.cxx b/reportdesign/source/core/api/ReportEngineJFree.cxx index 2a8b1cd0fb56..8b68da19e646 100644 --- a/reportdesign/source/core/api/ReportEngineJFree.cxx +++ b/reportdesign/source/core/api/ReportEngineJFree.cxx @@ -154,109 +154,103 @@ void SAL_CALL OReportEngineJFree::setStatusIndicator( const uno::Reference< task OUString OReportEngineJFree::getNewOutputName() { - OUString sOutputName; - { - ::osl::MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ReportEngineBase::rBHelper.bDisposed); - if ( !m_xReport.is() || !m_xActiveConnection.is() ) - throw lang::IllegalArgumentException(); + ::osl::MutexGuard aGuard(m_aMutex); + ::connectivity::checkDisposed(ReportEngineBase::rBHelper.bDisposed); + if ( !m_xReport.is() || !m_xActiveConnection.is() ) + throw lang::IllegalArgumentException(); - static const char s_sMediaType[] = "MediaType"; - try - { - MimeConfigurationHelper aConfighelper(m_xContext); - const OUString sMimeType = m_xReport->getMimeType(); - std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilter( aConfighelper.GetDocServiceNameFromMediaType(sMimeType) ); - OUString sExt(".rpt"); - if ( pFilter ) - sExt = ::comphelper::string::stripStart(pFilter->GetDefaultExtension(), '*'); - - uno::Reference< embed::XStorage > xTemp = OStorageHelper::GetTemporaryStorage(/*sFileTemp,embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE,*/ m_xContext); - utl::DisposableComponent aTemp(xTemp); - uno::Sequence< beans::PropertyValue > aEmpty; - uno::Reference< beans::XPropertySet> xStorageProp(xTemp,uno::UNO_QUERY); - if ( xStorageProp.is() ) - { - xStorageProp->setPropertyValue( s_sMediaType, uno::makeAny(sMimeType)); - } - m_xReport->storeToStorage(xTemp,aEmpty); // store to temp file because it may contain information which isn't in the database yet. - - uno::Sequence< beans::NamedValue > aConvertedProperties(8); - sal_Int32 nPos = 0; - aConvertedProperties[nPos].Name = "InputStorage"; - aConvertedProperties[nPos++].Value <<= xTemp; - aConvertedProperties[nPos].Name = "OutputStorage"; - - OUString sFileURL; - OUString sName = m_xReport->getCaption(); - if ( sName.isEmpty() ) - sName = m_xReport->getName(); - { - ::utl::TempFile aTestFile(sName, false, &sExt); - if ( !aTestFile.IsValid() ) - { - sName = RptResId(RID_STR_REPORT); - ::utl::TempFile aFile(sName, false, &sExt); - sFileURL = aFile.GetURL(); - } - else - sFileURL = aTestFile.GetURL(); - } + static const char s_sMediaType[] = "MediaType"; - uno::Reference< embed::XStorage > xOut = OStorageHelper::GetStorageFromURL(sFileURL,embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE, m_xContext); - utl::DisposableComponent aOut(xOut); - xStorageProp.set(xOut,uno::UNO_QUERY); - if ( xStorageProp.is() ) - { - xStorageProp->setPropertyValue( s_sMediaType, uno::makeAny(sMimeType)); - } + MimeConfigurationHelper aConfighelper(m_xContext); + const OUString sMimeType = m_xReport->getMimeType(); + std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilter( aConfighelper.GetDocServiceNameFromMediaType(sMimeType) ); + OUString sExt(".rpt"); + if ( pFilter ) + sExt = ::comphelper::string::stripStart(pFilter->GetDefaultExtension(), '*'); - aConvertedProperties[nPos++].Value <<= xOut; + uno::Reference< embed::XStorage > xTemp = OStorageHelper::GetTemporaryStorage(/*sFileTemp,embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE,*/ m_xContext); + utl::DisposableComponent aTemp(xTemp); + uno::Sequence< beans::PropertyValue > aEmpty; + uno::Reference< beans::XPropertySet> xStorageProp(xTemp,uno::UNO_QUERY); + if ( xStorageProp.is() ) + { + xStorageProp->setPropertyValue( s_sMediaType, uno::makeAny(sMimeType)); + } + m_xReport->storeToStorage(xTemp,aEmpty); // store to temp file because it may contain information which isn't in the database yet. + + uno::Sequence< beans::NamedValue > aConvertedProperties(8); + sal_Int32 nPos = 0; + aConvertedProperties[nPos].Name = "InputStorage"; + aConvertedProperties[nPos++].Value <<= xTemp; + aConvertedProperties[nPos].Name = "OutputStorage"; + + OUString sFileURL; + OUString sName = m_xReport->getCaption(); + if ( sName.isEmpty() ) + sName = m_xReport->getName(); + { + ::utl::TempFile aTestFile(sName, false, &sExt); + if ( !aTestFile.IsValid() ) + { + sName = RptResId(RID_STR_REPORT); + ::utl::TempFile aFile(sName, false, &sExt); + sFileURL = aFile.GetURL(); + } + else + sFileURL = aTestFile.GetURL(); + } - aConvertedProperties[nPos].Name = PROPERTY_REPORTDEFINITION; - aConvertedProperties[nPos++].Value <<= m_xReport; + uno::Reference< embed::XStorage > xOut = OStorageHelper::GetStorageFromURL(sFileURL,embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE, m_xContext); + utl::DisposableComponent aOut(xOut); + xStorageProp.set(xOut,uno::UNO_QUERY); + if ( xStorageProp.is() ) + { + xStorageProp->setPropertyValue( s_sMediaType, uno::makeAny(sMimeType)); + } - aConvertedProperties[nPos].Name = PROPERTY_ACTIVECONNECTION; - aConvertedProperties[nPos++].Value <<= m_xActiveConnection; + aConvertedProperties[nPos++].Value <<= xOut; - aConvertedProperties[nPos].Name = PROPERTY_MAXROWS; - aConvertedProperties[nPos++].Value <<= m_nMaxRows; + aConvertedProperties[nPos].Name = PROPERTY_REPORTDEFINITION; + aConvertedProperties[nPos++].Value <<= m_xReport; - // some meta data - SvtUserOptions aUserOpts; - OUStringBuffer sAuthor(aUserOpts.GetFirstName()); - sAuthor.append(" "); - sAuthor.append(aUserOpts.GetLastName()); - aConvertedProperties[nPos].Name = "Author"; - aConvertedProperties[nPos++].Value <<= sAuthor.makeStringAndClear(); + aConvertedProperties[nPos].Name = PROPERTY_ACTIVECONNECTION; + aConvertedProperties[nPos++].Value <<= m_xActiveConnection; - aConvertedProperties[nPos].Name = "Title"; - aConvertedProperties[nPos++].Value <<= m_xReport->getCaption(); + aConvertedProperties[nPos].Name = PROPERTY_MAXROWS; + aConvertedProperties[nPos++].Value <<= m_nMaxRows; - // create job factory and initialize - const OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xContext); - uno::Reference<task::XJob> xJob(m_xContext->getServiceManager()->createInstanceWithContext(sReportEngineServiceName,m_xContext),uno::UNO_QUERY_THROW); - if ( !m_xReport->getCommand().isEmpty() ) - { - xJob->execute(aConvertedProperties); - if ( xStorageProp.is() ) - { - sOutputName = sFileURL; - } - } + // some meta data + SvtUserOptions aUserOpts; + OUStringBuffer sAuthor(aUserOpts.GetFirstName()); + sAuthor.append(" "); + sAuthor.append(aUserOpts.GetLastName()); + aConvertedProperties[nPos].Name = "Author"; + aConvertedProperties[nPos++].Value <<= sAuthor.makeStringAndClear(); - uno::Reference<embed::XTransactedObject> xTransact(xOut,uno::UNO_QUERY); - if ( !sOutputName.isEmpty() && xTransact.is() ) - xTransact->commit(); + aConvertedProperties[nPos].Name = "Title"; + aConvertedProperties[nPos++].Value <<= m_xReport->getCaption(); - if ( sOutputName.isEmpty() ) - throw lang::IllegalArgumentException(); - } - catch(const uno::Exception&) + OUString sOutputName; + + // create job factory and initialize + const OUString sReportEngineServiceName = ::dbtools::getDefaultReportEngineServiceName(m_xContext); + uno::Reference<task::XJob> xJob(m_xContext->getServiceManager()->createInstanceWithContext(sReportEngineServiceName,m_xContext),uno::UNO_QUERY_THROW); + if ( !m_xReport->getCommand().isEmpty() ) + { + xJob->execute(aConvertedProperties); + if ( xStorageProp.is() ) { - throw; + sOutputName = sFileURL; } } + + uno::Reference<embed::XTransactedObject> xTransact(xOut,uno::UNO_QUERY); + if ( !sOutputName.isEmpty() && xTransact.is() ) + xTransact->commit(); + + if ( sOutputName.isEmpty() ) + throw lang::IllegalArgumentException(); + return sOutputName; } diff --git a/sd/source/ui/presenter/PresenterTextView.cxx b/sd/source/ui/presenter/PresenterTextView.cxx index 275718e1edcd..87679f849c11 100644 --- a/sd/source/ui/presenter/PresenterTextView.cxx +++ b/sd/source/ui/presenter/PresenterTextView.cxx @@ -119,18 +119,11 @@ void SAL_CALL PresenterTextView::initialize (const Sequence<Any>& rArguments) if (rArguments.getLength() == 1) { - try + Reference<rendering::XCanvas> xCanvas (rArguments[0], UNO_QUERY_THROW); + if (xCanvas.is()) { - Reference<rendering::XCanvas> xCanvas (rArguments[0], UNO_QUERY_THROW); - if (xCanvas.is()) - { - mpImplementation->SetCanvas( - cppcanvas::VCLFactory::createCanvas(xCanvas)); - } - } - catch (RuntimeException&) - { - throw; + mpImplementation->SetCanvas( + cppcanvas::VCLFactory::createCanvas(xCanvas)); } } else diff --git a/sd/source/ui/slidesorter/shell/SlideSorterService.cxx b/sd/source/ui/slidesorter/shell/SlideSorterService.cxx index b6ce91cc7ba2..ae14673c0afa 100644 --- a/sd/source/ui/slidesorter/shell/SlideSorterService.cxx +++ b/sd/source/ui/slidesorter/shell/SlideSorterService.cxx @@ -74,40 +74,32 @@ void SAL_CALL SlideSorterService::initialize (const Sequence<Any>& rArguments) static_cast<drawing::XDrawView*>(this)); } - try - { - mxViewId.set(rArguments[0], UNO_QUERY_THROW); - - // Get the XController. - Reference<frame::XController> xController (rArguments[1], UNO_QUERY_THROW); + mxViewId.set(rArguments[0], UNO_QUERY_THROW); - // Tunnel through the controller to obtain a ViewShellBase. - ViewShellBase* pBase = nullptr; - Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW); - ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( - xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); - if (pController != nullptr) - pBase = pController->GetViewShellBase(); + // Get the XController. + Reference<frame::XController> xController (rArguments[1], UNO_QUERY_THROW); - // Get the parent window. - mxParentWindow.set(rArguments[2], UNO_QUERY_THROW); - VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(mxParentWindow); + // Tunnel through the controller to obtain a ViewShellBase. + ViewShellBase* pBase = nullptr; + Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW); + ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( + xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); + if (pController != nullptr) + pBase = pController->GetViewShellBase(); - mxParentWindow->addWindowListener(this); + // Get the parent window. + mxParentWindow.set(rArguments[2], UNO_QUERY_THROW); + VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(mxParentWindow); - if (pBase != nullptr && pParentWindow) - mpSlideSorter = SlideSorter::CreateSlideSorter( - *pBase, - nullptr, - *pParentWindow); + mxParentWindow->addWindowListener(this); - Resize(); - } - catch (RuntimeException&) - { - throw; - } + if (pBase != nullptr && pParentWindow) + mpSlideSorter = SlideSorter::CreateSlideSorter( + *pBase, + nullptr, + *pParentWindow); + Resize(); } //----- XView ----------------------------------------------------------------- diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 2e48c03e90f4..d3907953cbb0 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -3298,20 +3298,14 @@ Reference< script::provider::XScriptProvider > SAL_CALL SfxBaseModel::getScriptP { SfxModelGuard aGuard( *this ); - Reference< script::provider::XScriptProvider > xScriptProvider; - Reference< script::provider::XScriptProviderFactory > xScriptProviderFactory = script::provider::theMasterScriptProviderFactory::get( ::comphelper::getProcessComponentContext() ); - try - { - Reference< XScriptInvocationContext > xScriptContext( this ); - xScriptProvider.set( xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), UNO_SET_THROW ); - } - catch( const RuntimeException& ) - { - throw; - } + Reference< XScriptInvocationContext > xScriptContext( this ); + + Reference< script::provider::XScriptProvider > xScriptProvider( + xScriptProviderFactory->createScriptProvider( makeAny( xScriptContext ) ), + UNO_SET_THROW ); return xScriptProvider; } diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk index 4a6928a72348..e622c9ae1ae3 100644 --- a/solenv/CompilerTest_compilerplugins_clang.mk +++ b/solenv/CompilerTest_compilerplugins_clang.mk @@ -36,6 +36,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \ compilerplugins/clang/test/salbool \ compilerplugins/clang/test/salunicodeliteral \ compilerplugins/clang/test/stringconstant \ + compilerplugins/clang/test/unnecessarycatchthrow \ compilerplugins/clang/test/unnecessaryoverride-dtor \ compilerplugins/clang/test/unnecessaryparen \ compilerplugins/clang/test/unoany \ diff --git a/ucb/source/cacher/cachedcontentresultset.cxx b/ucb/source/cacher/cachedcontentresultset.cxx index 4c160c3ed4e8..ea8ffc7ae18f 100644 --- a/ucb/source/cacher/cachedcontentresultset.cxx +++ b/ucb/source/cacher/cachedcontentresultset.cxx @@ -1408,18 +1408,7 @@ sal_Bool SAL_CALL CachedContentResultSet //unknown final count: aGuard.clear(); - // Solaris has problems catching or propagating derived exceptions - // when only the base class is known, so make ResultSetException - // (derived from SQLException) known here: - bool bValid; - try - { - bValid = m_xResultSetOrigin->absolute( row ); - } - catch (const ResultSetException&) - { - throw; - } + bool bValid = m_xResultSetOrigin->absolute( row ); aGuard.reset(); if( m_bFinalCount ) |