From 36b9475e7be42c904580154751aece697883a30a Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sun, 21 Mar 2021 20:49:22 +0900 Subject: devtools: don't store locally the object as XIndexAccess MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doesn't correctly read the IndexAccess if we remember it into a member variable, because we can't rely that the input object is cast to XIndexAccess, but use a getMainObject method to get a different object and cast that to XIndexAccess. So the instance of the object can change (object can be removed or and a new one added) and we have no way of knowing what the implementation does. It is possible to cache the XIndexAccess object into a member variable (if done carefully), but it is prone to the described problems so let's not remember any intermediate objects for all DocumentModelTreeEntry subclasses unless we actually have a performance problem. Change-Id: I9d9d30d2b43846d473d118d419d407e34d0b1666 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112836 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sfx2/source/devtools/DocumentModelTreeHandler.cxx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'sfx2/source/devtools') diff --git a/sfx2/source/devtools/DocumentModelTreeHandler.cxx b/sfx2/source/devtools/DocumentModelTreeHandler.cxx index a5b14ca42ab9..e099d3d9cc9d 100644 --- a/sfx2/source/devtools/DocumentModelTreeHandler.cxx +++ b/sfx2/source/devtools/DocumentModelTreeHandler.cxx @@ -658,13 +658,9 @@ public: /** Represents a list of (Calc) sheet */ class SheetsEntry : public DocumentModelTreeEntry { -private: - uno::Reference mxIndexAccess; - public: SheetsEntry(OUString const& rString, css::uno::Reference const& xObject) : DocumentModelTreeEntry(rString, xObject) - , mxIndexAccess(xObject, uno::UNO_QUERY) { } @@ -678,18 +674,20 @@ public: bool shouldShowExpander() override { - return mxIndexAccess.is() && mxIndexAccess->getCount() > 0; + uno::Reference xIndexAccess(getMainObject(), uno::UNO_QUERY); + return xIndexAccess.is() && xIndexAccess->getCount() > 0; } void fill(std::unique_ptr& pDocumentModelTree, weld::TreeIter const& rParent) override { - if (!mxIndexAccess.is()) + uno::Reference xIndexAccesss(getMainObject(), uno::UNO_QUERY); + if (!xIndexAccesss.is()) return; - for (sal_Int32 i = 0; i < mxIndexAccess->getCount(); ++i) + for (sal_Int32 i = 0; i < xIndexAccesss->getCount(); ++i) { - uno::Reference xSheet(mxIndexAccess->getByIndex(i), + uno::Reference xSheet(xIndexAccesss->getByIndex(i), uno::UNO_QUERY); OUString aString = lclGetNamed(xSheet); if (aString.isEmpty()) -- cgit