diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-03-21 20:49:22 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-03-21 15:57:44 +0100 |
commit | 36b9475e7be42c904580154751aece697883a30a (patch) | |
tree | 15b499fcb8792407df255609a19d2ae17571f1ae /sfx2/source/devtools | |
parent | b4ec5a94bd84017eb7db0b7f23d60265bbb9b040 (diff) |
devtools: don't store locally the object as XIndexAccess
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 <quikee@gmail.com>
Diffstat (limited to 'sfx2/source/devtools')
-rw-r--r-- | sfx2/source/devtools/DocumentModelTreeHandler.cxx | 14 |
1 files changed, 6 insertions, 8 deletions
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<container::XIndexAccess> mxIndexAccess; - public: SheetsEntry(OUString const& rString, css::uno::Reference<css::uno::XInterface> 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<container::XIndexAccess> xIndexAccess(getMainObject(), uno::UNO_QUERY); + return xIndexAccess.is() && xIndexAccess->getCount() > 0; } void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree, weld::TreeIter const& rParent) override { - if (!mxIndexAccess.is()) + uno::Reference<container::XIndexAccess> 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<sheet::XSpreadsheet> xSheet(mxIndexAccess->getByIndex(i), + uno::Reference<sheet::XSpreadsheet> xSheet(xIndexAccesss->getByIndex(i), uno::UNO_QUERY); OUString aString = lclGetNamed(xSheet); if (aString.isEmpty()) |