[Libreoffice-commits] core.git: sfx2/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Sun Mar 21 08:20:40 UTC 2021
sfx2/source/devtools/ObjectInspectorTreeHandler.cxx | 87 +++++++++++++-------
1 file changed, 58 insertions(+), 29 deletions(-)
New commits:
commit 296f39567b49d6edb054648e7e633ac0bb7111e1
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri Mar 19 15:48:33 2021 +0900
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Mar 21 09:19:56 2021 +0100
devtools: enclose calls with try/catch to handle exceptions
Some calls to UNO objects throw a RuntimeException if they aren't
implemented, so this makes it necessary to enclose calls to with
try/catch to prevent that exceptions propagate all the way to the
top (crashing the application).
Change-Id: I321171052906c4fe531377949a906689d2182771
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112787
Tested-by: Tomaž Vajngerl <quikee at gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
index 7884bdb4b88a..4e823fec2008 100644
--- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
+++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
@@ -683,48 +683,67 @@ void GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
if (!maAny.hasValue())
return;
- const auto xNameAccess = uno::Reference<container::XNameAccess>(maAny, uno::UNO_QUERY);
- if (xNameAccess.is())
+ try
{
- const uno::Sequence<OUString> aNames = xNameAccess->getElementNames();
- for (OUString const& rName : aNames)
+ const auto xNameAccess = uno::Reference<container::XNameAccess>(maAny, uno::UNO_QUERY);
+ if (xNameAccess.is())
{
- uno::Any aAny = xNameAccess->getByName(rName);
- auto* pObjectInspectorNode = createNodeObjectForAny(
- u"@" + rName, aAny, SfxResId(STR_PROPERTY_TYPE_IS_NAMED_CONTAINER));
- lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
+ const uno::Sequence<OUString> aNames = xNameAccess->getElementNames();
+ for (OUString const& rName : aNames)
+ {
+ uno::Any aAny = xNameAccess->getByName(rName);
+ auto* pObjectInspectorNode = createNodeObjectForAny(
+ u"@" + rName, aAny, SfxResId(STR_PROPERTY_TYPE_IS_NAMED_CONTAINER));
+ lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
+ }
}
}
-
- const auto xIndexAccess = uno::Reference<container::XIndexAccess>(maAny, uno::UNO_QUERY);
- if (xIndexAccess.is())
+ catch (...)
{
- for (sal_Int32 nIndex = 0; nIndex < xIndexAccess->getCount(); ++nIndex)
- {
- uno::Any aAny = xIndexAccess->getByIndex(nIndex);
- auto* pObjectInspectorNode
- = createNodeObjectForAny(u"@" + OUString::number(nIndex), aAny,
- SfxResId(STR_PROPERTY_TYPE_IS_INDEX_CONTAINER));
- lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
- }
}
- const auto xEnumAccess = uno::Reference<container::XEnumerationAccess>(maAny, uno::UNO_QUERY);
- if (xEnumAccess.is())
+ try
{
- uno::Reference<container::XEnumeration> xEnumeration = xEnumAccess->createEnumeration();
- if (xEnumeration.is())
+ const auto xIndexAccess = uno::Reference<container::XIndexAccess>(maAny, uno::UNO_QUERY);
+ if (xIndexAccess.is())
{
- for (sal_Int32 nIndex = 0; xEnumeration->hasMoreElements(); nIndex++)
+ for (sal_Int32 nIndex = 0; nIndex < xIndexAccess->getCount(); ++nIndex)
{
- uno::Any aAny = xEnumeration->nextElement();
+ uno::Any aAny = xIndexAccess->getByIndex(nIndex);
auto* pObjectInspectorNode
= createNodeObjectForAny(u"@" + OUString::number(nIndex), aAny,
- SfxResId(STR_PROPERTY_TYPE_IS_ENUMERATION));
+ SfxResId(STR_PROPERTY_TYPE_IS_INDEX_CONTAINER));
lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
}
}
}
+ catch (...)
+ {
+ }
+
+ try
+ {
+ const auto xEnumAccess
+ = uno::Reference<container::XEnumerationAccess>(maAny, uno::UNO_QUERY);
+ if (xEnumAccess.is())
+ {
+ uno::Reference<container::XEnumeration> xEnumeration = xEnumAccess->createEnumeration();
+ if (xEnumeration.is())
+ {
+ for (sal_Int32 nIndex = 0; xEnumeration->hasMoreElements(); nIndex++)
+ {
+ uno::Any aAny = xEnumeration->nextElement();
+ auto* pObjectInspectorNode
+ = createNodeObjectForAny(u"@" + OUString::number(nIndex), aAny,
+ SfxResId(STR_PROPERTY_TYPE_IS_ENUMERATION));
+ lclAppendNodeToParent(pTree, pParent, pObjectInspectorNode);
+ }
+ }
+ }
+ }
+ catch (...)
+ {
+ }
auto xInvocationFactory = css::script::Invocation::create(mxContext);
uno::Sequence<uno::Any> aParameters = { maAny };
@@ -736,10 +755,20 @@ void GenericPropertiesNode::fillChildren(std::unique_ptr<weld::TreeView>& pTree,
if (!xInvocation.is())
return;
- const auto xInvocationAccess = xInvocation->getIntrospection();
+ auto const& xInvocationAccess = xInvocation->getIntrospection();
+ if (!xInvocationAccess.is())
+ return;
+
+ uno::Sequence<script::InvocationInfo> aInvocationInfoSequence;
+ try
+ {
+ aInvocationInfoSequence = xInvocation->getInfo();
+ }
+ catch (...)
+ {
+ }
- const auto aInvocationInfoSequence = xInvocation->getInfo();
- for (auto const& aInvocationInfo : aInvocationInfoSequence)
+ for (auto const& aInvocationInfo : std::as_const(aInvocationInfoSequence))
{
if (aInvocationInfo.eMemberType == script::MemberType_PROPERTY)
{
More information about the Libreoffice-commits
mailing list