[Libreoffice-commits] core.git: linguistic/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Tue Aug 10 13:08:13 UTC 2021
linguistic/source/lngsvcmgr.cxx | 116 +++++++++++++++++-----------------------
1 file changed, 51 insertions(+), 65 deletions(-)
New commits:
commit f989bd22cc3c80d3c5119e3de1a269ab9a80bd78
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Aug 10 10:13:04 2021 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Aug 10 15:07:35 2021 +0200
Catch exceptions when setting up linguistic extensions
...not only from the createInstance calls, but also from later calls like
XSpellChecker::getLocales. At least when installing
<https://www.puimula.org/htp/ooo/voikko-win/5.0.2.20170827/voikko.oxt> (which
only contains native code for macOS and Windows) on Linux, that getLocales call
would cause a RuntimeException, but which was effectively left uncaught and thus
caused a crash.
Change-Id: Id06760cb91b9aef2f3bbfe94213e40146214903d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120260
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/linguistic/source/lngsvcmgr.cxx b/linguistic/source/lngsvcmgr.cxx
index b4b8d3836f6e..a0f9822e4779 100644
--- a/linguistic/source/lngsvcmgr.cxx
+++ b/linguistic/source/lngsvcmgr.cxx
@@ -940,7 +940,6 @@ void LngSvcMgr::GetAvailableSpellSvcs_Impl()
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
- uno::Reference< linguistic2::XSpellChecker > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
@@ -950,27 +949,24 @@ void LngSvcMgr::GetAvailableSpellSvcs_Impl()
{
try
{
- xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
+ uno::Reference< linguistic2::XSpellChecker > xSvc( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY_THROW );
+
+ OUString aImplName;
+ std::vector< LanguageType > aLanguages;
+ uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
+ if (xInfo.is())
+ aImplName = xInfo->getImplementationName();
+ SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
+ uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
+ aLanguages = LocaleSeqToLangVec( aLocaleSequence );
+
+ pAvailSpellSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
-
- if (xSvc.is())
- {
- OUString aImplName;
- std::vector< LanguageType > aLanguages;
- uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
- if (xInfo.is())
- aImplName = xInfo->getImplementationName();
- SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
- uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
- aLanguages = LocaleSeqToLangVec( aLocaleSequence );
-
- pAvailSpellSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
- }
}
}
@@ -998,7 +994,6 @@ void LngSvcMgr::GetAvailableGrammarSvcs_Impl()
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
- uno::Reference< linguistic2::XProofreader > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
@@ -1008,13 +1003,24 @@ void LngSvcMgr::GetAvailableGrammarSvcs_Impl()
{
try
{
- if (xCompFactory.is())
- {
- xSvc.set(xCompFactory->createInstanceWithContext(xContext), uno::UNO_QUERY);
- }
- else
+ uno::Reference< linguistic2::XProofreader > xSvc(
+ xCompFactory.is()
+ ? xCompFactory->createInstanceWithContext(xContext)
+ : xFactory->createInstance(),
+ uno::UNO_QUERY_THROW);
+
+ if (pAvailGrammarSvcs)
{
- xSvc.set(xFactory->createInstance(), uno::UNO_QUERY);
+ OUString aImplName;
+ std::vector< LanguageType > aLanguages;
+ uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
+ if (xInfo.is())
+ aImplName = xInfo->getImplementationName();
+ SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
+ uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
+ aLanguages = LocaleSeqToLangVec( aLocaleSequence );
+
+ pAvailGrammarSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
}
catch (const uno::Exception &)
@@ -1023,19 +1029,6 @@ void LngSvcMgr::GetAvailableGrammarSvcs_Impl()
}
}
- if (xSvc.is() && pAvailGrammarSvcs)
- {
- OUString aImplName;
- std::vector< LanguageType > aLanguages;
- uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
- if (xInfo.is())
- aImplName = xInfo->getImplementationName();
- SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
- uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
- aLanguages = LocaleSeqToLangVec( aLocaleSequence );
-
- pAvailGrammarSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
- }
}
}
@@ -1062,7 +1055,6 @@ void LngSvcMgr::GetAvailableHyphSvcs_Impl()
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
- uno::Reference< linguistic2::XHyphenator > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
@@ -1072,25 +1064,22 @@ void LngSvcMgr::GetAvailableHyphSvcs_Impl()
{
try
{
- xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
+ uno::Reference< linguistic2::XHyphenator > xSvc( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY_THROW );
+ OUString aImplName;
+ std::vector< LanguageType > aLanguages;
+ uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
+ if (xInfo.is())
+ aImplName = xInfo->getImplementationName();
+ SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
+ uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
+ aLanguages = LocaleSeqToLangVec( aLocaleSequence );
+ pAvailHyphSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
- if (xSvc.is())
- {
- OUString aImplName;
- std::vector< LanguageType > aLanguages;
- uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
- if (xInfo.is())
- aImplName = xInfo->getImplementationName();
- SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
- uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
- aLanguages = LocaleSeqToLangVec( aLocaleSequence );
- pAvailHyphSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
- }
}
}
@@ -1118,7 +1107,6 @@ void LngSvcMgr::GetAvailableThesSvcs_Impl()
uno::Reference< lang::XSingleComponentFactory > xCompFactory;
uno::Reference< lang::XSingleServiceFactory > xFactory;
- uno::Reference< linguistic2::XThesaurus > xSvc;
xCompFactory.set(aCurrent, css::uno::UNO_QUERY);
if (!xCompFactory.is())
{
@@ -1128,26 +1116,24 @@ void LngSvcMgr::GetAvailableThesSvcs_Impl()
{
try
{
- xSvc.set( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY );
+ uno::Reference< linguistic2::XThesaurus > xSvc( ( xCompFactory.is() ? xCompFactory->createInstanceWithContext( xContext ) : xFactory->createInstance() ), uno::UNO_QUERY_THROW );
+
+ OUString aImplName;
+ std::vector< LanguageType > aLanguages;
+ uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
+ if (xInfo.is())
+ aImplName = xInfo->getImplementationName();
+ SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
+ uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
+ aLanguages = LocaleSeqToLangVec( aLocaleSequence );
+
+ pAvailThesSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
}
catch (const uno::Exception &)
{
SAL_WARN( "linguistic", "createInstance failed" );
}
}
- if (xSvc.is())
- {
- OUString aImplName;
- std::vector< LanguageType > aLanguages;
- uno::Reference< XServiceInfo > xInfo( xSvc, uno::UNO_QUERY );
- if (xInfo.is())
- aImplName = xInfo->getImplementationName();
- SAL_WARN_IF( aImplName.isEmpty(), "linguistic", "empty implementation name" );
- uno::Sequence<lang::Locale> aLocaleSequence(xSvc->getLocales());
- aLanguages = LocaleSeqToLangVec( aLocaleSequence );
-
- pAvailThesSvcs->push_back( std::make_unique<SvcInfo>( aImplName, aLanguages ) );
- }
}
}
More information about the Libreoffice-commits
mailing list