cui/source/dialogs/SignSignatureLineDialog.cxx        |    8 +
 cui/source/dialogs/srchxtra.cxx                       |   62 ++++-----
 cui/source/dialogs/zoom.cxx                           |    8 -
 cui/source/tabpages/autocdlg.cxx                      |    3 
 cui/source/tabpages/border.cxx                        |    3 
 cui/source/tabpages/chardlg.cxx                       |    7 -
 cui/source/tabpages/numfmt.cxx                        |    8 -
 cui/source/tabpages/numpages.cxx                      |   15 +-
 cui/source/tabpages/page.cxx                          |    3 
 cui/source/tabpages/paragrph.cxx                      |    6 
 desktop/source/lib/init.cxx                           |    8 -
 extensions/source/bibliography/general.cxx            |    3 
 include/svx/ClassificationDialog.hxx                  |    5 
 sc/source/ui/attrdlg/attrdlg.cxx                      |    2 
 sc/source/ui/drawfunc/drtxtob.cxx                     |   13 +-
 sc/source/ui/styleui/styledlg.cxx                     |    3 
 sc/source/ui/view/editsh.cxx                          |    5 
 scripting/source/protocolhandler/scripthandler.cxx    |    3 
 sd/source/ui/animations/CustomAnimationDialog.cxx     |    3 
 sd/source/ui/app/sdmod2.cxx                           |    5 
 sd/source/ui/sidebar/SlideBackground.cxx              |   54 +++++---
 sd/source/ui/view/drviews2.cxx                        |   34 +++--
 sfx2/source/dialog/securitypage.cxx                   |    8 -
 svx/source/dialog/ClassificationDialog.cxx            |    7 -
 svx/source/form/datanavi.cxx                          |    2 
 svx/source/sidebar/area/AreaPropertyPanelBase.cxx     |   75 ++++++------
 svx/source/sidebar/nbdtmg.cxx                         |    8 -
 svx/source/tbxctrls/fillctrl.cxx                      |   27 ++--
 svx/source/tbxctrls/linectrl.cxx                      |    8 -
 sw/source/core/edit/edfcol.cxx                        |   16 +-
 sw/source/ui/dialog/docstdlg.cxx                      |    4 
 sw/source/ui/fldui/fldedt.cxx                         |    4 
 sw/source/uibase/app/docsh2.cxx                       |   50 ++++----
 sw/source/uibase/ribbar/workctrl.cxx                  |    8 -
 sw/source/uibase/shells/annotsh.cxx                   |    5 
 sw/source/uibase/shells/drwtxtex.cxx                  |    3 
 sw/source/uibase/sidebar/PageStylesPanel.cxx          |  112 ++++++++++--------
 sw/source/uibase/sidebar/StylePresetsPanel.cxx        |   15 +-
 sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx |   20 +--
 39 files changed, 348 insertions(+), 285 deletions(-)

New commits:
commit 8e807647c266ea0ebf4c10ed61187690cfd65f52
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Fri Dec 16 12:11:38 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sat Dec 17 14:41:39 2022 +0000

    check SfxObjectShell::Current()
    
    SfxObjectShell::Current() can return null, it's based on the equally
    vile SfxViewFrame::Current()
    
    Change-Id: Ia5c7783680e9d8e5d3075078f16a2c15cb6f7a47
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144355
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/cui/source/dialogs/SignSignatureLineDialog.cxx 
b/cui/source/dialogs/SignSignatureLineDialog.cxx
index 1f1bd4551080..94306764b201 100644
--- a/cui/source/dialogs/SignSignatureLineDialog.cxx
+++ b/cui/source/dialogs/SignSignatureLineDialog.cxx
@@ -156,7 +156,7 @@ IMPL_LINK_NOARG(SignSignatureLineDialog, chooseCertificate, 
weld::Button&, void)
 {
     // Document needs to be saved before selecting a certificate
     SfxObjectShell* pShell = SfxObjectShell::Current();
-    if (!pShell->PrepareForSigning(m_xDialog.get()))
+    if (!pShell || !pShell->PrepareForSigning(m_xDialog.get()))
         return;
 
     Reference<XCertificate> xSignCertificate
@@ -193,6 +193,12 @@ void SignSignatureLineDialog::Apply()
     }
 
     SfxObjectShell* pShell = SfxObjectShell::Current();
+    if (!pShell)
+    {
+        SAL_WARN("cui.dialogs", "No SfxObjectShell!");
+        return;
+    }
+
     Reference<XGraphic> xValidGraphic = getSignedGraphic(true);
     Reference<XGraphic> xInvalidGraphic = getSignedGraphic(false);
     pShell->SignSignatureLine(m_xDialog.get(), m_aSignatureLineId, 
m_xSelectedCertifate,
diff --git a/cui/source/dialogs/srchxtra.cxx b/cui/source/dialogs/srchxtra.cxx
index d857f77c42df..40c2e369ab6b 100644
--- a/cui/source/dialogs/srchxtra.cxx
+++ b/cui/source/dialogs/srchxtra.cxx
@@ -64,9 +64,7 @@ void SvxSearchFormatDialog::PageCreated(const OString& rId, 
SfxTabPage& rPage)
     if (rId == "font")
     {
         const FontList* pApm_pFontList = nullptr;
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-
-        if ( pSh )
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
         {
             const SvxFontListItem* pFLItem = static_cast<const 
SvxFontListItem*>(
                 pSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
@@ -119,42 +117,44 @@ 
SvxSearchAttributeDialog::SvxSearchAttributeDialog(weld::Window* pParent,
 
     SfxObjectShell* pSh = SfxObjectShell::Current();
     DBG_ASSERT( pSh, "No DocShell" );
-
-    SfxItemPool& rPool = pSh->GetPool();
-    SfxItemSet aSet( rPool, pWhRanges );
-    SfxWhichIter aIter( aSet );
-    sal_uInt16 nWhich = aIter.FirstWhich();
-
-    while ( nWhich )
+    if (pSh)
     {
-        sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
-        if ( nSlot >= SID_SVX_START )
+        SfxItemPool& rPool = pSh->GetPool();
+        SfxItemSet aSet( rPool, pWhRanges );
+        SfxWhichIter aIter( aSet );
+        sal_uInt16 nWhich = aIter.FirstWhich();
+
+        while ( nWhich )
         {
-            bool bChecked = false, bFound = false;
-            for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
+            sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
+            if ( nSlot >= SID_SVX_START )
             {
-                if ( nSlot == rList[i].nSlot )
+                bool bChecked = false, bFound = false;
+                for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
                 {
-                    bFound = true;
-                    if ( IsInvalidItem( rList[i].pItem ) )
-                        bChecked = true;
+                    if ( nSlot == rList[i].nSlot )
+                    {
+                        bFound = true;
+                        if ( IsInvalidItem( rList[i].pItem ) )
+                            bChecked = true;
+                    }
                 }
-            }
 
-            // item resources are in svx
-            sal_uInt32 nId  = SvxAttrNameTable::FindIndex(nSlot);
-            if (RESARRAY_INDEX_NOTFOUND != nId)
-            {
-                m_xAttrLB->append();
-                const int nRow = m_xAttrLB->n_children() - 1;
-                m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : 
TRISTATE_FALSE);
-                m_xAttrLB->set_text(nRow, SvxAttrNameTable::GetString(nId), 0);
-                m_xAttrLB->set_id(nRow, OUString::number(nSlot));
+                // item resources are in svx
+                sal_uInt32 nId  = SvxAttrNameTable::FindIndex(nSlot);
+                if (RESARRAY_INDEX_NOTFOUND != nId)
+                {
+                    m_xAttrLB->append();
+                    const int nRow = m_xAttrLB->n_children() - 1;
+                    m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : 
TRISTATE_FALSE);
+                    m_xAttrLB->set_text(nRow, 
SvxAttrNameTable::GetString(nId), 0);
+                    m_xAttrLB->set_id(nRow, OUString::number(nSlot));
+                }
+                else
+                    SAL_WARN( "cui.dialogs", "no resource for slot id " << 
static_cast<sal_Int32>(nSlot) );
             }
-            else
-                SAL_WARN( "cui.dialogs", "no resource for slot id " << 
static_cast<sal_Int32>(nSlot) );
+            nWhich = aIter.NextWhich();
         }
-        nWhich = aIter.NextWhich();
     }
 
     m_xAttrLB->make_sorted();
diff --git a/cui/source/dialogs/zoom.cxx b/cui/source/dialogs/zoom.cxx
index 0c9b189dd0f1..0d6f44e405fd 100644
--- a/cui/source/dialogs/zoom.cxx
+++ b/cui/source/dialogs/zoom.cxx
@@ -168,9 +168,7 @@ SvxZoomDialog::SvxZoomDialog(weld::Window* pParent, const 
SfxItemSet& rCoreSet)
 
     // maybe get the old value first
     const SfxUInt16Item* pOldUserItem = nullptr;
-    SfxObjectShell* pShell = SfxObjectShell::Current();
-
-    if (pShell)
+    if (SfxObjectShell* pShell = SfxObjectShell::Current())
         pOldUserItem = pShell->GetItem(SID_ATTR_ZOOM_USER);
 
     if (pOldUserItem)
@@ -384,9 +382,7 @@ IMPL_LINK_NOARG(SvxZoomDialog, OKHdl, weld::Button&, void)
             m_pOutSet->Put(aViewLayoutItem);
 
         // memorize value from the UserEdit beyond the dialog
-        SfxObjectShell* pShell = SfxObjectShell::Current();
-
-        if (pShell)
+        if (SfxObjectShell* pShell = SfxObjectShell::Current())
         {
             sal_uInt16 nZoomValue
                 = 
static_cast<sal_uInt16>(m_xUserEdit->get_value(FieldUnit::PERCENT));
diff --git a/cui/source/tabpages/autocdlg.cxx b/cui/source/tabpages/autocdlg.cxx
index 2947c16e3730..2c978a835922 100644
--- a/cui/source/tabpages/autocdlg.cxx
+++ b/cui/source/tabpages/autocdlg.cxx
@@ -769,7 +769,8 @@ bool OfaAutocorrReplacePage::FillItemSet( SfxItemSet* )
             bool bKeepSourceFormatting = newEntry.pUserData == 
&bHasSelectionText;
             if (bKeepSourceFormatting)
             {
-                pAutoCorrect->PutText(newEntry.sShort, 
*SfxObjectShell::Current(), eCurrentLang);
+                if (SfxObjectShell* pSh = SfxObjectShell::Current())
+                    pAutoCorrect->PutText(newEntry.sShort, *pSh, eCurrentLang);
                 continue;
             }
 
diff --git a/cui/source/tabpages/border.cxx b/cui/source/tabpages/border.cxx
index 336e3f57bb26..9b94bc0eb28a 100644
--- a/cui/source/tabpages/border.cxx
+++ b/cui/source/tabpages/border.cxx
@@ -574,8 +574,7 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, 
weld::DialogControlle
     // checkbox "Merge adjacent line styles" only visible for Writer dialog 
format.table
     m_xMergeAdjacentBordersCB->hide();
 
-    SfxObjectShell* pDocSh = SfxObjectShell::Current();
-    if (pDocSh)
+    if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
     {
         Reference< XServiceInfo > xSI( pDocSh->GetModel(), UNO_QUERY );
         if ( xSI.is() )
diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx
index 3d77e2a338fb..3fff1a62352a 100644
--- a/cui/source/tabpages/chardlg.cxx
+++ b/cui/source/tabpages/chardlg.cxx
@@ -344,10 +344,8 @@ const FontList* SvxCharNamePage::GetFontList() const
 {
     if ( !m_pImpl->m_pFontList )
     {
-        SfxObjectShell* pDocSh = SfxObjectShell::Current();
-
         /* #110771# SvxFontListItem::GetFontList can return NULL */
-        if ( pDocSh )
+        if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
         {
             const SfxPoolItem* pItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST 
);
             if ( pItem != nullptr )
@@ -1366,8 +1364,7 @@ void SvxCharEffectsPage::Initialize()
     const SfxUInt16Item* pHtmlModeItem = GetItemSet().GetItemIfSet( 
SID_HTML_MODE, false );
     if ( !pHtmlModeItem)
     {
-        SfxObjectShell* pShell = SfxObjectShell::Current();
-        if (pShell)
+        if (SfxObjectShell* pShell = SfxObjectShell::Current())
            pHtmlModeItem = pShell->GetItem( SID_HTML_MODE );
     }
     if (pHtmlModeItem)
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index 54b5b53d9aac..f48a3b60c95e 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -475,8 +475,7 @@ void SvxNumberFormatTabPage::Reset( const SfxItemSet* rSet )
 
 
     bool bUseStarFormat = false;
-    SfxObjectShell* pDocSh  = SfxObjectShell::Current();
-    if ( pDocSh )
+    if (SfxObjectShell* pDocSh  = SfxObjectShell::Current())
     {
         // is this a calc document
         Reference< XServiceInfo > xSI( pDocSh->GetModel(), UNO_QUERY );
@@ -714,11 +713,8 @@ bool SvxNumberFormatTabPage::FillItemSet( SfxItemSet* 
rCoreAttrs )
             else
             {
                 SfxObjectShell* pDocSh  = SfxObjectShell::Current();
-
                 DBG_ASSERT( pDocSh, "DocShell not found!" );
-
-
-                if ( pDocSh )
+                if (pDocSh)
                     pDocSh->PutItem( *pNumItem );
             }
         }
diff --git a/cui/source/tabpages/numpages.cxx b/cui/source/tabpages/numpages.cxx
index 57648fa612db..0c66f69ee637 100644
--- a/cui/source/tabpages/numpages.cxx
+++ b/cui/source/tabpages/numpages.cxx
@@ -645,11 +645,13 @@ IMPL_LINK_NOARG(SvxNumPickTabPage, NumSelectHdl_Impl, 
ValueSet*, void)
                 //search for the font
                 if(!pList)
                 {
-                    SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
-                    const SvxFontListItem* pFontListItem =
-                            static_cast<const SvxFontListItem*>( pCurDocShell
-                                                ->GetItem( 
SID_ATTR_CHAR_FONTLIST ));
-                    pList = pFontListItem ? pFontListItem->GetFontList() : 
nullptr;
+                    if (SfxObjectShell* pCurDocShell = 
SfxObjectShell::Current())
+                    {
+                        const SvxFontListItem* pFontListItem =
+                                static_cast<const SvxFontListItem*>( 
pCurDocShell
+                                                    ->GetItem( 
SID_ATTR_CHAR_FONTLIST ));
+                        pList = pFontListItem ? pFontListItem->GetFontList() : 
nullptr;
+                    }
                 }
                 if(pList && pList->IsAvailable( pLevelSettings->sBulletFont ) )
                 {
@@ -1243,8 +1245,7 @@ void    SvxNumOptionsTabPage::Reset( const SfxItemSet* 
rSet )
         rSet->GetItemIfSet( SID_HTML_MODE, false );
     if (!pHtmlModeItem)
     {
-        SfxObjectShell* pShell = SfxObjectShell::Current();
-        if (pShell)
+        if (SfxObjectShell* pShell = SfxObjectShell::Current())
             pHtmlModeItem = pShell->GetItem( SID_HTML_MODE );
     }
     if ( pHtmlModeItem )
diff --git a/cui/source/tabpages/page.cxx b/cui/source/tabpages/page.cxx
index bf57c645bd74..7af647f02d9b 100644
--- a/cui/source/tabpages/page.cxx
+++ b/cui/source/tabpages/page.cxx
@@ -199,8 +199,7 @@ SvxPageDescPage::SvxPageDescPage(weld::Container* pPage, 
weld::DialogController*
     const SfxUInt16Item* pHtmlModeItem = rAttr.GetItemIfSet(SID_HTML_MODE, 
false);
     if (!pHtmlModeItem)
     {
-        SfxObjectShell* pShell = SfxObjectShell::Current();
-        if (pShell)
+        if (SfxObjectShell* pShell = SfxObjectShell::Current())
             pHtmlModeItem = pShell->GetItem(SID_HTML_MODE);
     }
     if (pHtmlModeItem)
diff --git a/cui/source/tabpages/paragrph.cxx b/cui/source/tabpages/paragrph.cxx
index e9171a62dd04..ff6426b499aa 100644
--- a/cui/source/tabpages/paragrph.cxx
+++ b/cui/source/tabpages/paragrph.cxx
@@ -148,8 +148,7 @@ static sal_uInt16 GetHtmlMode_Impl(const SfxItemSet& rSet)
     const SfxUInt16Item* pItem = rSet.GetItemIfSet(SID_HTML_MODE, false);
     if (!pItem)
     {
-        SfxObjectShell* pShell = SfxObjectShell::Current();
-        if (pShell)
+        if (SfxObjectShell* pShell = SfxObjectShell::Current())
             pItem = pShell->GetItem(SID_HTML_MODE);
     }
     if(pItem)
@@ -1999,8 +1998,7 @@ 
SvxExtParagraphTabPage::SvxExtParagraphTabPage(weld::Container* pPage, weld::Dia
     m_xPageNumBox->connect_toggled(LINK(this, SvxExtParagraphTabPage, 
PageNumBoxClickHdl_Impl));
     m_xKeepParaBox->connect_toggled(LINK(this, SvxExtParagraphTabPage, 
KeepParaBoxClickHdl_Impl));
 
-    SfxObjectShell* pSh = SfxObjectShell::Current();
-    if ( pSh )
+    if (SfxObjectShell* pSh = SfxObjectShell::Current())
     {
         SfxStyleSheetBasePool* pPool = pSh->GetStyleSheetPool();
         SfxStyleSheetBase* pStyle = pPool->First(SfxStyleFamily::Page);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index fd99214e6daa..3b80e6e14bd1 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1232,6 +1232,8 @@ rtl::Reference<LOKClipboard> 
forceSetClipboardForCurrentView(LibreOfficeKitDocum
 const vcl::Font* FindFont(std::u16string_view rFontName)
 {
     SfxObjectShell* pDocSh = SfxObjectShell::Current();
+    if (!pDocSh)
+        return nullptr;
     const SvxFontListItem* pFonts
         = static_cast<const 
SvxFontListItem*>(pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
     const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr;
@@ -4580,7 +4582,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* 
pThis, const char* pComma
     {
         // Check if saving a PDF file
         OUString aMimeType = lcl_getCurrentDocumentMimeType(pDocument);
-        if (pDocSh->IsModified() && aMimeType == "application/pdf")
+        if (pDocSh && pDocSh->IsModified() && aMimeType == "application/pdf")
         {
             // If we have a PDF file (for saving annotations for example), we 
need
             // to run save-as to the same file as the opened document. Plain 
save
@@ -4621,7 +4623,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* 
pThis, const char* pComma
                                                    }), 
aPropertyValuesVector.end());
 
         // skip saving and tell the result via UNO_COMMAND_RESULT
-        if (bDontSaveIfUnmodified && !pDocSh->IsModified())
+        if (bDontSaveIfUnmodified && (!pDocSh || !pDocSh->IsModified()))
         {
             tools::JsonWriter aJson;
             aJson.put("commandName", pCommand);
@@ -5393,6 +5395,8 @@ static char* getLanguages(const char* pCommand)
 static char* getFonts (const char* pCommand)
 {
     SfxObjectShell* pDocSh = SfxObjectShell::Current();
+    if (!pDocSh)
+        return nullptr;
     const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>(
         pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
     const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr;
diff --git a/extensions/source/bibliography/general.cxx 
b/extensions/source/bibliography/general.cxx
index f6b60fb92afe..41ed9cd1929f 100644
--- a/extensions/source/bibliography/general.cxx
+++ b/extensions/source/bibliography/general.cxx
@@ -362,9 +362,8 @@ IMPL_LINK_NOARG(BibGeneralPage, BrowseHdl, weld::Button&, 
void)
     }
     else
     {
-        SfxObjectShell* pShell = SfxObjectShell::Current();
         OUString aBaseURL;
-        if (pShell)
+        if (SfxObjectShell* pShell = SfxObjectShell::Current())
         {
             aBaseURL = pShell->getDocumentBaseURL();
         }
diff --git a/include/svx/ClassificationDialog.hxx 
b/include/svx/ClassificationDialog.hxx
index 24bffe2ea41f..dd96b5bab1bb 100644
--- a/include/svx/ClassificationDialog.hxx
+++ b/include/svx/ClassificationDialog.hxx
@@ -82,8 +82,9 @@ private:
     void toggleWidgetsDependingOnCategory();
 
 public:
-    ClassificationDialog(weld::Window* pParent, bool bPerParagraph,
-                         std::function<void()> aParagraphSignHandler = []() 
{});
+    ClassificationDialog(weld::Window* pParent,
+                         const 
css::uno::Reference<css::document::XDocumentProperties>& rDocProps,
+                         bool bPerParagraph, std::function<void()> 
aParagraphSignHandler = []() {});
     ~ClassificationDialog() override;
 
     std::vector<ClassificationResult> getResult();
diff --git a/sc/source/ui/attrdlg/attrdlg.cxx b/sc/source/ui/attrdlg/attrdlg.cxx
index 4c761ef7b36f..734ae94d606f 100644
--- a/sc/source/ui/attrdlg/attrdlg.cxx
+++ b/sc/source/ui/attrdlg/attrdlg.cxx
@@ -72,7 +72,7 @@ void ScAttrDlg::PageCreated(const OString& rPageId, 
SfxTabPage& rTabPage)
     {
         rTabPage.PageCreated(aSet);
     }
-    else if (rPageId == "font")
+    else if (rPageId == "font" && pDocSh)
     {
         const SfxPoolItem* pInfoItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST 
);
         assert(pInfoItem && "FontListItem  not found :-(");
diff --git a/sc/source/ui/drawfunc/drtxtob.cxx 
b/sc/source/ui/drawfunc/drtxtob.cxx
index 5d2e5a2e4019..37a493178e39 100644
--- a/sc/source/ui/drawfunc/drtxtob.cxx
+++ b/sc/source/ui/drawfunc/drtxtob.cxx
@@ -820,11 +820,14 @@ void ScDrawTextObjectBar::ExecuteAttr( SfxRequest &rReq )
                     pView->GetTextEditOutlinerView() : nullptr;
                 if ( pOutView )
                 {
-                    const SvxFontListItem* pFontListItem = static_cast< const 
SvxFontListItem* >
-                            ( SfxObjectShell::Current()->GetItem( 
SID_ATTR_CHAR_FONTLIST ) );
-                    const FontList* pFontList = pFontListItem ? 
pFontListItem->GetFontList() : nullptr;
-                    pOutView->GetEditView().ChangeFontSize( nSlot == 
SID_GROW_FONT_SIZE, pFontList );
-                    mrViewData.GetBindings().Invalidate( 
SID_ATTR_CHAR_FONTHEIGHT );
+                    if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
+                    {
+                        const SvxFontListItem* pFontListItem = static_cast< 
const SvxFontListItem* >
+                                ( pObjSh->GetItem( SID_ATTR_CHAR_FONTLIST ) );
+                        const FontList* pFontList = pFontListItem ? 
pFontListItem->GetFontList() : nullptr;
+                        pOutView->GetEditView().ChangeFontSize( nSlot == 
SID_GROW_FONT_SIZE, pFontList );
+                        mrViewData.GetBindings().Invalidate( 
SID_ATTR_CHAR_FONTHEIGHT );
+                    }
                     bDone = false;
                 }
             }
diff --git a/sc/source/ui/styleui/styledlg.cxx 
b/sc/source/ui/styleui/styledlg.cxx
index 892fe4ac2a95..d814654e5008 100644
--- a/sc/source/ui/styleui/styledlg.cxx
+++ b/sc/source/ui/styleui/styledlg.cxx
@@ -99,9 +99,8 @@ void ScStyleDlg::PageCreated(const OString& rPageId, 
SfxTabPage& rTabPage)
             rTabPage.PageCreated(aSet);
         }
     }
-    else
+    else if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
     {
-        SfxObjectShell* pDocSh = SfxObjectShell::Current();
         SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
         if (rPageId == "numbers")
         {
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index bdd0d32d551b..2b36efa11ec8 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -1140,8 +1140,9 @@ void ScEditShell::ExecuteAttr(SfxRequest& rReq)
         case SID_GROW_FONT_SIZE:
         case SID_SHRINK_FONT_SIZE:
             {
-                const SvxFontListItem* pFontListItem = static_cast< const 
SvxFontListItem* >
-                        ( SfxObjectShell::Current()->GetItem( 
SID_ATTR_CHAR_FONTLIST ) );
+                SfxObjectShell* pObjSh = SfxObjectShell::Current();
+                const SvxFontListItem* pFontListItem = static_cast<const 
SvxFontListItem*>
+                        (pObjSh ? pObjSh->GetItem(SID_ATTR_CHAR_FONTLIST) : 
nullptr);
                 const FontList* pFontList = pFontListItem ? 
pFontListItem->GetFontList() : nullptr;
                 pEditView->ChangeFontSize( nSlot == SID_GROW_FONT_SIZE, 
pFontList );
                 rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
diff --git a/scripting/source/protocolhandler/scripthandler.cxx 
b/scripting/source/protocolhandler/scripthandler.cxx
index d05c34612c45..5aabb4654b0a 100644
--- a/scripting/source/protocolhandler/scripthandler.cxx
+++ b/scripting/source/protocolhandler/scripthandler.cxx
@@ -327,8 +327,7 @@ ScriptProtocolHandler::getScriptInvocation()
                     if ( pFrame->GetFrameInterface() == m_xFrame )
                         break;
                 }
-                SfxObjectShell* pDocShell = pFrame ? 
pFrame->GetCurrentDocument() : SfxObjectShell::Current();
-                if ( pDocShell )
+                if (SfxObjectShell* pDocShell = pFrame ? 
pFrame->GetCurrentDocument() : SfxObjectShell::Current())
                 {
                     Reference< XModel > xModel( pDocShell->GetModel() );
                     m_xScriptInvocation.set( xModel, UNO_QUERY );
diff --git a/sd/source/ui/animations/CustomAnimationDialog.cxx 
b/sd/source/ui/animations/CustomAnimationDialog.cxx
index 625a3049695e..41d7685798d4 100644
--- a/sd/source/ui/animations/CustomAnimationDialog.cxx
+++ b/sd/source/ui/animations/CustomAnimationDialog.cxx
@@ -265,11 +265,10 @@ SdFontPropertyBox::SdFontPropertyBox(weld::Label* pLabel, 
weld::Container* pPare
     mxControl->show();
     pLabel->set_mnemonic_widget(mxControl.get());
 
-    SfxObjectShell* pDocSh = SfxObjectShell::Current();
     const FontList* pFontList = nullptr;
     bool bMustDelete = false;
 
-    if (pDocSh)
+    if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
     {
         auto pItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
         if (pItem)
diff --git a/sd/source/ui/app/sdmod2.cxx b/sd/source/ui/app/sdmod2.cxx
index 58c822c47bc4..cccf425172bc 100644
--- a/sd/source/ui/app/sdmod2.cxx
+++ b/sd/source/ui/app/sdmod2.cxx
@@ -342,10 +342,11 @@ IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, 
pInfo, void)
     {
         try
         {
-            if (SfxObjectShell::Current() && 
SfxObjectShell::Current()->IsLoadingFinished())
+            SfxObjectShell* pObjSh = SfxObjectShell::Current();
+            if (pObjSh && pObjSh->IsLoadingFinished())
             {
                 auto pNonConstCustomPropertyField = 
const_cast<editeng::CustomPropertyField*>(pCustomPropertyField);
-                OUString sCurrent = 
pNonConstCustomPropertyField->GetFormatted(SfxObjectShell::Current()->getDocProperties());
+                OUString sCurrent = 
pNonConstCustomPropertyField->GetFormatted(pObjSh->getDocProperties());
                 pInfo->SetRepresentation(sCurrent);
             }
             else
diff --git a/sd/source/ui/sidebar/SlideBackground.cxx 
b/sd/source/ui/sidebar/SlideBackground.cxx
index 11f49dff67eb..5f8bcff886b7 100644
--- a/sd/source/ui/sidebar/SlideBackground.cxx
+++ b/sd/source/ui/sidebar/SlideBackground.cxx
@@ -754,11 +754,14 @@ XGradient const & 
SlideBackground::GetGradientSetOrDefault()
 {
     if( !mpGradientItem )
     {
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-        const SvxGradientListItem * pGradListItem = 
pSh->GetItem(SID_GRADIENT_LIST);
-        const XGradient aGradient = 
pGradListItem->GetGradientList()->GetGradient(0)->GetGradient();
-        const OUString aGradientName = 
pGradListItem->GetGradientList()->GetGradient(0)->GetName();
-
+        XGradient aGradient;
+        OUString aGradientName;
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
+        {
+            const SvxGradientListItem * pGradListItem = 
pSh->GetItem(SID_GRADIENT_LIST);
+            aGradient = 
pGradListItem->GetGradientList()->GetGradient(0)->GetGradient();
+            aGradientName = 
pGradListItem->GetGradientList()->GetGradient(0)->GetName();
+        }
         mpGradientItem.reset( new XFillGradientItem( aGradientName, aGradient 
) );
     }
 
@@ -769,11 +772,14 @@ OUString const & 
SlideBackground::GetHatchingSetOrDefault()
 {
     if( !mpHatchItem )
     {
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-        const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST);
-        const XHatch aHatch = 
pHatchListItem->GetHatchList()->GetHatch(0)->GetHatch();
-        const OUString aHatchName = 
pHatchListItem->GetHatchList()->GetHatch(0)->GetName();
-
+        XHatch aHatch;
+        OUString aHatchName;
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
+        {
+            const SvxHatchListItem * pHatchListItem = 
pSh->GetItem(SID_HATCH_LIST);
+            aHatch = pHatchListItem->GetHatchList()->GetHatch(0)->GetHatch();
+            aHatchName = 
pHatchListItem->GetHatchList()->GetHatch(0)->GetName();
+        }
         mpHatchItem.reset( new XFillHatchItem( aHatchName, aHatch ) );
     }
 
@@ -784,11 +790,14 @@ OUString const & SlideBackground::GetBitmapSetOrDefault()
 {
     if( !mpBitmapItem || mpBitmapItem->isPattern())
     {
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-        const SvxBitmapListItem * pBmpListItem = pSh->GetItem(SID_BITMAP_LIST);
-        const GraphicObject aGraphObj = 
pBmpListItem->GetBitmapList()->GetBitmap(0)->GetGraphicObject();
-        const OUString aBmpName = 
pBmpListItem->GetBitmapList()->GetBitmap(0)->GetName();
-
+        GraphicObject aGraphObj;
+        OUString aBmpName;
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
+        {
+            const SvxBitmapListItem * pBmpListItem = 
pSh->GetItem(SID_BITMAP_LIST);
+            aGraphObj = 
pBmpListItem->GetBitmapList()->GetBitmap(0)->GetGraphicObject();
+            aBmpName = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetName();
+        }
         mpBitmapItem.reset( new XFillBitmapItem( aBmpName, aGraphObj ) );
     }
 
@@ -799,11 +808,14 @@ OUString const & SlideBackground::GetPatternSetOrDefault()
 {
     if( !mpBitmapItem || !(mpBitmapItem->isPattern()))
     {
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-        const SvxPatternListItem * pPtrnListItem = 
pSh->GetItem(SID_PATTERN_LIST);
-        const GraphicObject aGraphObj = 
pPtrnListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject();
-        const OUString aPtrnName = 
pPtrnListItem->GetPatternList()->GetBitmap(0)->GetName();
-
+        GraphicObject aGraphObj;
+        OUString aPtrnName;
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
+        {
+            const SvxPatternListItem * pPtrnListItem = 
pSh->GetItem(SID_PATTERN_LIST);
+            aGraphObj = 
pPtrnListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject();
+            aPtrnName = 
pPtrnListItem->GetPatternList()->GetBitmap(0)->GetName();
+        }
         mpBitmapItem.reset( new XFillBitmapItem( aPtrnName, aGraphObj ) );
     }
 
@@ -1134,6 +1146,8 @@ IMPL_LINK_NOARG(SlideBackground, FillBackgroundHdl, 
weld::ComboBox&, void)
 {
     const eFillStyle nFillPos = 
static_cast<eFillStyle>(mxFillStyle->get_active());
     SfxObjectShell* pSh = SfxObjectShell::Current();
+    if (!pSh)
+        return;
     switch(nFillPos)
     {
 
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index d197852c9026..c53ba142b7bb 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -244,9 +244,9 @@ protected:
     uno::Reference<beans::XPropertyContainer> m_xPropertyContainer;
     sfx::ClassificationKeyCreator m_aKeyCreator;
 public:
-    ClassificationCommon(sd::DrawViewShell & rDrawViewShell)
+    ClassificationCommon(sd::DrawViewShell& rDrawViewShell, const 
css::uno::Reference<css::document::XDocumentProperties>& rDocProps)
         : m_rDrawViewShell(rDrawViewShell)
-        , m_xDocumentProperties(SfxObjectShell::Current()->getDocProperties())
+        , m_xDocumentProperties(rDocProps)
         , 
m_xPropertyContainer(m_xDocumentProperties->getUserDefinedProperties())
         , m_aKeyCreator(SfxClassificationHelper::getPolicyType())
     {}
@@ -306,8 +306,8 @@ private:
     }
 
 public:
-    ClassificationCollector(sd::DrawViewShell & rDrawViewShell)
-        : ClassificationCommon(rDrawViewShell)
+    ClassificationCollector(sd::DrawViewShell & rDrawViewShell, const 
css::uno::Reference<css::document::XDocumentProperties>& rDocProps)
+        : ClassificationCommon(rDrawViewShell, rDocProps)
     {}
 
     std::vector<svx::ClassificationResult> const & getResults() const
@@ -461,8 +461,8 @@ private:
     }
 
 public:
-    ClassificationInserter(sd::DrawViewShell & rDrawViewShell)
-        : ClassificationCommon(rDrawViewShell)
+    ClassificationInserter(sd::DrawViewShell & rDrawViewShell, const 
css::uno::Reference<css::document::XDocumentProperties>& rDocProps)
+        : ClassificationCommon(rDrawViewShell, rDocProps)
     {
     }
 
@@ -1689,18 +1689,22 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
 
         case SID_CLASSIFICATION_DIALOG:
         {
-            auto xDialog = 
std::make_shared<svx::ClassificationDialog>(GetFrameWeld(), false, [](){} );
-            ClassificationCollector aCollector(*this);
-            aCollector.collect();
+            if (SfxObjectShell* pObjShell = SfxObjectShell::Current())
+            {
+                css::uno::Reference<css::document::XDocumentProperties> 
xDocProps(pObjShell->getDocProperties());
+                auto xDialog = 
std::make_shared<svx::ClassificationDialog>(GetFrameWeld(), xDocProps, false, 
[](){} );
+                ClassificationCollector aCollector(*this, xDocProps);
+                aCollector.collect();
 
-            xDialog->setupValues(std::vector(aCollector.getResults()));
+                xDialog->setupValues(std::vector(aCollector.getResults()));
 
-            if (RET_OK == xDialog->run())
-            {
-                ClassificationInserter aInserter(*this);
-                aInserter.insert(xDialog->getResult());
+                if (RET_OK == xDialog->run())
+                {
+                    ClassificationInserter aInserter(*this, xDocProps);
+                    aInserter.insert(xDialog->getResult());
+                }
+                xDialog.reset();
             }
-            xDialog.reset();
 
             Cancel();
             rReq.Ignore();
diff --git a/sfx2/source/dialog/securitypage.cxx 
b/sfx2/source/dialog/securitypage.cxx
index 39bdc7cb1eba..a07eb4ace212 100644
--- a/sfx2/source/dialog/securitypage.cxx
+++ b/sfx2/source/dialog/securitypage.cxx
@@ -108,9 +108,11 @@ static bool lcl_GetPassword(
 
 static bool lcl_IsPasswordCorrect( std::u16string_view rPassword )
 {
-    bool bRes = false;
-
     SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
+    if (!pCurDocShell)
+        return false;
+
+    bool bRes = false;
     uno::Sequence< sal_Int8 >   aPasswordHash;
     pCurDocShell->GetProtectionHash( aPasswordHash );
 
@@ -199,7 +201,7 @@ bool SfxSecurityPage_Impl::FillItemSet_Impl()
     bool bModified = false;
 
     SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
-    if (pCurDocShell&& !pCurDocShell->IsReadOnly())
+    if (pCurDocShell && !pCurDocShell->IsReadOnly())
     {
         if (m_eRedlingMode != RL_NONE )
         {
diff --git a/svx/source/dialog/ClassificationDialog.cxx 
b/svx/source/dialog/ClassificationDialog.cxx
index e815f995aa56..8a6c26edda24 100644
--- a/svx/source/dialog/ClassificationDialog.cxx
+++ b/svx/source/dialog/ClassificationDialog.cxx
@@ -155,10 +155,11 @@ void writeResultToXml(tools::XmlWriter & rXmlWriter,
 
 } // end anonymous namespace
 
-ClassificationDialog::ClassificationDialog(weld::Window* pParent, const bool 
bPerParagraph, std::function<void()> aParagraphSignHandler)
+ClassificationDialog::ClassificationDialog(weld::Window* pParent, const 
css::uno::Reference<css::document::XDocumentProperties>& rDocProps,
+                                           const bool bPerParagraph, 
std::function<void()> aParagraphSignHandler)
     : GenericDialogController(pParent, "svx/ui/classificationdialog.ui", 
"AdvancedDocumentClassificationDialog")
-    , maHelper(SfxObjectShell::Current()->getDocProperties())
-    , maInternationalHelper(SfxObjectShell::Current()->getDocProperties(), 
/*bUseLocalizedPolicy*/ false)
+    , maHelper(rDocProps)
+    , maInternationalHelper(rDocProps, /*bUseLocalizedPolicy*/ false)
     , m_bPerParagraph(bPerParagraph)
     , m_aParagraphSignHandler(std::move(aParagraphSignHandler))
     , m_nCurrentSelectedCategory(-1)
diff --git a/svx/source/form/datanavi.cxx b/svx/source/form/datanavi.cxx
index 5592ad8002a4..210ebdce3b22 100644
--- a/svx/source/form/datanavi.cxx
+++ b/svx/source/form/datanavi.cxx
@@ -1926,7 +1926,7 @@ namespace svxform
     {
         SfxObjectShell* pCurrentDoc = SfxObjectShell::Current();
         DBG_ASSERT( pCurrentDoc, "DataNavigatorWindow::SetDocModified(): no 
objectshell" );
-        if ( !pCurrentDoc->IsModified() && pCurrentDoc->IsEnableSetModified() )
+        if (pCurrentDoc && !pCurrentDoc->IsModified() && 
pCurrentDoc->IsEnableSetModified())
             pCurrentDoc->SetModified();
     }
 
diff --git a/svx/source/sidebar/area/AreaPropertyPanelBase.cxx 
b/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
index b11f61d775eb..996026d1fa6c 100644
--- a/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
+++ b/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
@@ -203,31 +203,39 @@ IMPL_LINK_NOARG(AreaPropertyPanelBase, 
ClickImportBitmapHdl, weld::Button&, void
     if( nError != ERRCODE_NONE )
         return;
 
-    XBitmapListRef pList = 
SfxObjectShell::Current()->GetItem(SID_BITMAP_LIST)->GetBitmapList();
-    INetURLObject   aURL( aDlg.GetPath() );
-    OUString aFileName = aURL.GetLastName().getToken(0, '.');
-    OUString aName = aFileName;
-    tools::Long j = 1;
-    bool bValidBitmapName = false;
-    while( !bValidBitmapName )
+    mxLbFillAttr->clear();
+
+    if (SfxObjectShell* pSh = SfxObjectShell::Current())
     {
-        bValidBitmapName = true;
-        for( tools::Long i = 0; i < pList->Count() && bValidBitmapName; i++ )
+        INetURLObject aURL(aDlg.GetPath());
+        OUString aFileName = aURL.GetLastName().getToken(0, '.');
+        OUString aName = aFileName;
+
+        XBitmapListRef pList = pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList();
+
+        tools::Long j = 1;
+        bool bValidBitmapName = false;
+        while( !bValidBitmapName )
         {
-            if( aName == pList->GetBitmap(i)->GetName() )
+            bValidBitmapName = true;
+            for( tools::Long i = 0; i < pList->Count() && bValidBitmapName; 
i++ )
             {
-                bValidBitmapName = false;
-                aName = aFileName + OUString::number(j++);
+                if( aName == pList->GetBitmap(i)->GetName() )
+                {
+                    bValidBitmapName = false;
+                    aName = aFileName + OUString::number(j++);
+                }
             }
         }
-    }
 
-    pList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName));
-    pList->Save();
-    mxLbFillAttr->clear();
-    SvxFillAttrBox::Fill(*mxLbFillAttr, pList);
-    mxLbFillAttr->set_active_text(aName);
-    SelectFillAttrHdl(*mxLbFillAttr);
+        pList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName));
+        pList->Save();
+
+        SvxFillAttrBox::Fill(*mxLbFillAttr, pList);
+
+        mxLbFillAttr->set_active_text(aName);
+        SelectFillAttrHdl(*mxLbFillAttr);
+    }
 }
 
 IMPL_LINK_NOARG(AreaPropertyPanelBase, SelectFillTypeHdl, weld::ComboBox&, 
void)
@@ -285,7 +293,7 @@ void AreaPropertyPanelBase::SelectFillAttrHdl_Impl()
         case eFillStyle::GRADIENT:
         {
 
-            if(pSh && pSh->GetItem(SID_COLOR_TABLE))
+            if (pSh && pSh->GetItem(SID_COLOR_TABLE))
             {
                 XGradient aGradient;
                 
aGradient.SetAngle(Degree10(mxMTRAngle->get_value(FieldUnit::DEGREE) * 10));
@@ -1097,10 +1105,12 @@ void AreaPropertyPanelBase::NotifyItemUpdate(
                     {
                         const OUString aString( mpFillGradientItem->GetName() 
);
                         const SfxObjectShell* pSh = SfxObjectShell::Current();
-
                         mxLbFillAttr->clear();
-                        mxLbFillAttr->set_sensitive(true);
-                        SvxFillAttrBox::Fill(*mxLbFillAttr, 
pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
+                        if (pSh)
+                        {
+                            mxLbFillAttr->set_sensitive(true);
+                            SvxFillAttrBox::Fill(*mxLbFillAttr, 
pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
+                        }
                         mxLbFillAttr->set_active_text(aString);
                     }
                     else
@@ -1121,10 +1131,12 @@ void AreaPropertyPanelBase::NotifyItemUpdate(
                     {
                         const OUString aString( mpHatchItem->GetName() );
                         const SfxObjectShell* pSh = SfxObjectShell::Current();
-
                         mxLbFillAttr->clear();
-                        mxLbFillAttr->set_sensitive(true);
-                        SvxFillAttrBox::Fill(*mxLbFillAttr, 
pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
+                        if (pSh)
+                        {
+                            mxLbFillAttr->set_sensitive(true);
+                            SvxFillAttrBox::Fill(*mxLbFillAttr, 
pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
+                        }
                         mxLbFillAttr->set_active_text(aString);
                     }
                     else
@@ -1148,13 +1160,12 @@ void AreaPropertyPanelBase::NotifyItemUpdate(
                         const SfxObjectShell* pSh = SfxObjectShell::Current();
                         mxLbFillAttr->clear();
                         mxLbFillAttr->show();
-                        if(nSID == SID_BITMAP_LIST)
-                        {
-                            SvxFillAttrBox::Fill(*mxLbFillAttr, 
pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
-                        }
-                        else if(nSID == SID_PATTERN_LIST)
+                        if (pSh)
                         {
-                            SvxFillAttrBox::Fill(*mxLbFillAttr, 
pSh->GetItem(SID_PATTERN_LIST)->GetPatternList());
+                            if(nSID == SID_BITMAP_LIST)
+                                SvxFillAttrBox::Fill(*mxLbFillAttr, 
pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
+                            else if(nSID == SID_PATTERN_LIST)
+                                SvxFillAttrBox::Fill(*mxLbFillAttr, 
pSh->GetItem(SID_PATTERN_LIST)->GetPatternList());
                         }
                         mxLbFillAttr->set_active_text(aString);
                     }
diff --git a/svx/source/sidebar/nbdtmg.cxx b/svx/source/sidebar/nbdtmg.cxx
index 55557eb0ff17..241b91673836 100644
--- a/svx/source/sidebar/nbdtmg.cxx
+++ b/svx/source/sidebar/nbdtmg.cxx
@@ -786,9 +786,11 @@ void OutlineTypeMgr::ApplyNumRule(SvxNumRule& aNum, 
sal_uInt16 nIndex, sal_uInt1
                 //search for the font
                 if(!pList)
                 {
-                    SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
-                    const SvxFontListItem* pFontListItem = static_cast<const 
SvxFontListItem*>( pCurDocShell->GetItem( SID_ATTR_CHAR_FONTLIST ) );
-                    pList = pFontListItem ? pFontListItem->GetFontList() : 
nullptr;
+                    if (SfxObjectShell* pCurDocShell = 
SfxObjectShell::Current())
+                    {
+                        const SvxFontListItem* pFontListItem = 
static_cast<const 
SvxFontListItem*>(pCurDocShell->GetItem(SID_ATTR_CHAR_FONTLIST));
+                        pList = pFontListItem ? pFontListItem->GetFontList() : 
nullptr;
+                    }
                 }
                 if(pList && pList->IsAvailable( pLevelSettings->sBulletFont ) )
                 {
diff --git a/svx/source/tbxctrls/fillctrl.cxx b/svx/source/tbxctrls/fillctrl.cxx
index 980c0f819e71..cfb7583be12c 100644
--- a/svx/source/tbxctrls/fillctrl.cxx
+++ b/svx/source/tbxctrls/fillctrl.cxx
@@ -275,11 +275,12 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl(
                     if(mpFillGradientItem)
                     {
                         const OUString aString( mpFillGradientItem->GetName() 
);
-                        const SfxObjectShell* pSh = SfxObjectShell::Current();
-
                         mpLbFillAttr->clear();
-                        mpLbFillAttr->set_sensitive(true);
-                        SvxFillAttrBox::Fill(*mpLbFillAttr, 
pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
+                        if (const SfxObjectShell* pSh = 
SfxObjectShell::Current())
+                        {
+                            mpLbFillAttr->set_sensitive(true);
+                            SvxFillAttrBox::Fill(*mpLbFillAttr, 
pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
+                        }
                         mpLbFillAttr->set_active_text(aString);
                     }
                     else
@@ -299,11 +300,12 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl(
                     if(mpHatchItem)
                     {
                         const OUString aString( mpHatchItem->GetName() );
-                        const SfxObjectShell* pSh = SfxObjectShell::Current();
-
                         mpLbFillAttr->clear();
-                        mpLbFillAttr->set_sensitive(true);
-                        SvxFillAttrBox::Fill(*mpLbFillAttr, 
pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
+                        if (const SfxObjectShell* pSh = 
SfxObjectShell::Current())
+                        {
+                            mpLbFillAttr->set_sensitive(true);
+                            SvxFillAttrBox::Fill(*mpLbFillAttr, 
pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
+                        }
                         mpLbFillAttr->set_active_text(aString);
                     }
                     else
@@ -323,11 +325,12 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl(
                     if(mpBitmapItem)
                     {
                         const OUString aString( mpBitmapItem->GetName() );
-                        const SfxObjectShell* pSh = SfxObjectShell::Current();
-
                         mpLbFillAttr->clear();
-                        mpLbFillAttr->set_sensitive(true);
-                        SvxFillAttrBox::Fill(*mpLbFillAttr, 
pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
+                        if (const SfxObjectShell* pSh = 
SfxObjectShell::Current())
+                        {
+                            mpLbFillAttr->set_sensitive(true);
+                            SvxFillAttrBox::Fill(*mpLbFillAttr, 
pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
+                        }
                         mpLbFillAttr->set_active_text(aString);
                     }
                     else
diff --git a/svx/source/tbxctrls/linectrl.cxx b/svx/source/tbxctrls/linectrl.cxx
index 81f064fc78f4..9fcaeb22b919 100644
--- a/svx/source/tbxctrls/linectrl.cxx
+++ b/svx/source/tbxctrls/linectrl.cxx
@@ -599,14 +599,12 @@ IMPL_LINK_NOARG(SvxLineBox, SelectHdl, ValueSet*, void)
         default:
         {
             eXLS = drawing::LineStyle_DASH;
-
-            if ( nPos != -1 &&
-                 SfxObjectShell::Current()  &&
-                 SfxObjectShell::Current()->GetItem( SID_DASH_LIST ) )
+            const SfxObjectShell* pObjSh = SfxObjectShell::Current();
+            if (nPos != -1 && pObjSh && pObjSh->GetItem(SID_DASH_LIST))
             {
                 // LineDashItem will only be sent if it also has a dash.
                 // Notify cares!
-                SvxDashListItem const * pItem = 
SfxObjectShell::Current()->GetItem( SID_DASH_LIST );
+                SvxDashListItem const * pItem = pObjSh->GetItem( SID_DASH_LIST 
);
                 const XDashEntry* pEntry = pItem->GetDashList()->GetDash(nPos 
- 2);
                 XLineDashItem aLineDashItem(pEntry->GetName(), 
pEntry->GetDash());
 
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx
index 6b7852997d60..dbd9d5bb30dd 100644
--- a/sw/source/core/edit/edfcol.cxx
+++ b/sw/source/core/edit/edfcol.cxx
@@ -777,7 +777,11 @@ static void 
equaliseNumberOfParagraph(std::vector<svx::ClassificationResult> con
 void 
SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationResult> 
const & rResults)
 {
     SwDocShell* pDocShell = GetDoc()->GetDocShell();
-    if (!pDocShell || !SfxObjectShell::Current())
+    if (!pDocShell)
+        return;
+
+    const SfxObjectShell* pObjSh = SfxObjectShell::Current();
+    if (!pObjSh)
         return;
 
     uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
@@ -787,7 +791,7 @@ void 
SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
 
     uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, 
uno::UNO_QUERY);
 
-    uno::Reference<document::XDocumentProperties> xDocumentProperties = 
SfxObjectShell::Current()->getDocProperties();
+    uno::Reference<document::XDocumentProperties> xDocumentProperties = 
pObjSh->getDocProperties();
 
     const OUString sPolicy = 
SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
     const std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
@@ -949,12 +953,16 @@ std::vector<svx::ClassificationResult> 
SwEditShell::CollectAdvancedClassificatio
     std::vector<svx::ClassificationResult> aResult;
 
     SwDocShell* pDocShell = GetDoc()->GetDocShell();
-    if (!pDocShell || !SfxObjectShell::Current())
+    if (!pDocShell)
+        return aResult;
+
+    const SfxObjectShell* pObjSh = SfxObjectShell::Current();
+    if (!pObjSh)
         return aResult;
 
     const OUString sBlank;
 
-    uno::Reference<document::XDocumentProperties> xDocumentProperties = 
SfxObjectShell::Current()->getDocProperties();
+    uno::Reference<document::XDocumentProperties> xDocumentProperties = 
pObjSh->getDocProperties();
     uno::Reference<beans::XPropertyContainer> xPropertyContainer = 
xDocumentProperties->getUserDefinedProperties();
     sfx::ClassificationKeyCreator 
aCreator(SfxClassificationHelper::getPolicyType());
 
diff --git a/sw/source/ui/dialog/docstdlg.cxx b/sw/source/ui/dialog/docstdlg.cxx
index 2701ec015e6c..48e4642281ea 100644
--- a/sw/source/ui/dialog/docstdlg.cxx
+++ b/sw/source/ui/dialog/docstdlg.cxx
@@ -54,7 +54,7 @@ SwDocStatPage::SwDocStatPage(weld::Container* pPage, 
weld::DialogController* pCo
     m_xUpdatePB->connect_clicked(LINK(this, SwDocStatPage, UpdateHdl));
     //#111684# is the current view a page preview no SwFEShell can be found -> 
hide the update button
     SwDocShell* pDocShell = static_cast<SwDocShell*>( 
SfxObjectShell::Current() );
-    SwFEShell* pFEShell = pDocShell->GetFEShell();
+    SwFEShell* pFEShell = pDocShell ? pDocShell->GetFEShell() : nullptr;
     if(!pFEShell)
     {
         m_xUpdatePB->hide();
@@ -118,7 +118,7 @@ IMPL_LINK_NOARG(SwDocStatPage, UpdateHdl, weld::Button&, 
void)
 {
     Update();
     SwDocShell* pDocShell = static_cast<SwDocShell*>( 
SfxObjectShell::Current());
-    SwFEShell* pFEShell = pDocShell->GetFEShell();
+    SwFEShell* pFEShell = pDocShell ? pDocShell->GetFEShell() : nullptr;
     if (pFEShell)
         m_xLineNo->set_label(OUString::number(pFEShell->GetLineCount()));
 }
diff --git a/sw/source/ui/fldui/fldedt.cxx b/sw/source/ui/fldui/fldedt.cxx
index 6e0ca5caf07e..e4f5824f9ad9 100644
--- a/sw/source/ui/fldui/fldedt.cxx
+++ b/sw/source/ui/fldui/fldedt.cxx
@@ -187,8 +187,8 @@ SfxTabPage* SwFieldEditDlg::CreatePage(sal_uInt16 nGroup)
             xTabPage = SwFieldRefPage::Create(get_content_area(), this, 
nullptr);
             break;
         case GRP_REG:
+            if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
             {
-                SfxObjectShell* pDocSh = SfxObjectShell::Current();
                 auto pSet = new SfxItemSetFixed<FN_FIELD_DIALOG_DOC_PROPS, 
FN_FIELD_DIALOG_DOC_PROPS>( pDocSh->GetPool() );
                 using namespace ::com::sun::star;
                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
@@ -200,8 +200,8 @@ SfxTabPage* SwFieldEditDlg::CreatePage(sal_uInt16 nGroup)
                     uno::UNO_QUERY_THROW);
                 pSet->Put( SfxUnoAnyItem( FN_FIELD_DIALOG_DOC_PROPS, 
uno::Any(xUDProps) ) );
                 xTabPage = SwFieldDokInfPage::Create(get_content_area(), this, 
pSet);
-                break;
             }
+            break;
 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
         case GRP_DB:
             xTabPage = SwFieldDBPage::Create(get_content_area(), this, 
nullptr);
diff --git a/sw/source/uibase/app/docsh2.cxx b/sw/source/uibase/app/docsh2.cxx
index ef3c607444e5..bc9647d77dd7 100644
--- a/sw/source/uibase/app/docsh2.cxx
+++ b/sw/source/uibase/app/docsh2.cxx
@@ -1223,36 +1223,38 @@ void SwDocShell::Execute(SfxRequest& rReq)
         }
         break;
         case SID_CLASSIFICATION_DIALOG:
-        {
-            auto xDialog = 
std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), false);
+            if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
+            {
+                auto xDialog = 
std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), 
pObjSh->getDocProperties(), false);
 
-            SwWrtShell* pShell = GetWrtShell();
-            std::vector<svx::ClassificationResult> aInput = 
pShell->CollectAdvancedClassification();
-            xDialog->setupValues(std::move(aInput));
+                SwWrtShell* pShell = GetWrtShell();
+                std::vector<svx::ClassificationResult> aInput = 
pShell->CollectAdvancedClassification();
+                xDialog->setupValues(std::move(aInput));
 
-            weld::DialogController::runAsync(xDialog, [xDialog, 
pShell](sal_Int32 nResult){
-                if (RET_OK == nResult)
-                    pShell->ApplyAdvancedClassification(xDialog->getResult());
-            });
-        }
-        break;
+                weld::DialogController::runAsync(xDialog, [xDialog, 
pShell](sal_Int32 nResult){
+                    if (RET_OK == nResult)
+                        
pShell->ApplyAdvancedClassification(xDialog->getResult());
+                });
+            }
+            break;
         case SID_PARAGRAPH_SIGN_CLASSIFY_DLG:
-        {
-            SwWrtShell* pShell = GetWrtShell();
-            auto xDialog = 
std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), true, 
[pShell]()
+            if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
             {
-                pShell->SignParagraph();
-            });
+                SwWrtShell* pShell = GetWrtShell();
+                auto xDialog = 
std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), 
pObjSh->getDocProperties(), true, [pShell]()
+                {
+                    pShell->SignParagraph();
+                });
 
-            std::vector<svx::ClassificationResult> aInput = 
pShell->CollectParagraphClassification();
-            xDialog->setupValues(std::move(aInput));
+                std::vector<svx::ClassificationResult> aInput = 
pShell->CollectParagraphClassification();
+                xDialog->setupValues(std::move(aInput));
 
-            weld::DialogController::runAsync(xDialog, [xDialog, 
pShell](sal_Int32 nResult){
-                if (RET_OK == nResult)
-                    pShell->ApplyParagraphClassification(xDialog->getResult());
-            });
-        }
-        break;
+                weld::DialogController::runAsync(xDialog, [xDialog, 
pShell](sal_Int32 nResult){
+                    if (RET_OK == nResult)
+                        
pShell->ApplyParagraphClassification(xDialog->getResult());
+                });
+            }
+            break;
         case SID_WATERMARK:
         {
             SwWrtShell* pSh = GetWrtShell();
diff --git a/sw/source/uibase/ribbar/workctrl.cxx 
b/sw/source/uibase/ribbar/workctrl.cxx
index 53c747e478ed..312ae0ddfb64 100644
--- a/sw/source/uibase/ribbar/workctrl.cxx
+++ b/sw/source/uibase/ribbar/workctrl.cxx
@@ -560,9 +560,11 @@ IMPL_LINK_NOARG(SwJumpToSpecificBox_Impl, SelectHdl, 
weld::Entry&, bool)
     OUString sEntry(m_xWidget->get_text());
     SfxUInt16Item aPageNum(m_nSlotId);
     aPageNum.SetValue(o3tl::narrowing<sal_uInt16>(sEntry.toInt32()));
-    SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
-    pCurrentShell->GetDispatcher()->ExecuteList(m_nSlotId, 
SfxCallMode::ASYNCHRON,
-            { &aPageNum });
+    if (SfxObjectShell* pCurrentShell = SfxObjectShell::Current())
+    {
+        pCurrentShell->GetDispatcher()->ExecuteList(m_nSlotId, 
SfxCallMode::ASYNCHRON,
+                { &aPageNum });
+    }
     return true;
 }
 
diff --git a/sw/source/uibase/shells/annotsh.cxx 
b/sw/source/uibase/shells/annotsh.cxx
index 3dcfc6a4a346..6318c7bf7852 100644
--- a/sw/source/uibase/shells/annotsh.cxx
+++ b/sw/source/uibase/shells/annotsh.cxx
@@ -224,8 +224,9 @@ void SwAnnotationShell::Exec( SfxRequest &rReq )
         case FN_GROW_FONT_SIZE:
         case FN_SHRINK_FONT_SIZE:
         {
-            const SvxFontListItem* pFontListItem = static_cast< const 
SvxFontListItem* >
-                    ( SfxObjectShell::Current()->GetItem( 
SID_ATTR_CHAR_FONTLIST ) );
+            const SfxObjectShell* pObjSh = SfxObjectShell::Current();
+            const SvxFontListItem* pFontListItem = static_cast<const 
SvxFontListItem*>
+                    (pObjSh ? pObjSh->GetItem(SID_ATTR_CHAR_FONTLIST) : 
nullptr);
             const FontList* pFontList = pFontListItem ? 
pFontListItem->GetFontList() : nullptr;
             pOLV->GetEditView().ChangeFontSize( nSlot == FN_GROW_FONT_SIZE, 
pFontList );
         }
diff --git a/sw/source/uibase/shells/drwtxtex.cxx 
b/sw/source/uibase/shells/drwtxtex.cxx
index 9f23ed7e6b7d..c84ee7bd9af4 100644
--- a/sw/source/uibase/shells/drwtxtex.cxx
+++ b/sw/source/uibase/shells/drwtxtex.cxx
@@ -624,8 +624,9 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
         case FN_GROW_FONT_SIZE:
         case FN_SHRINK_FONT_SIZE:
         {
+            const SfxObjectShell* pObjSh = SfxObjectShell::Current();
             const SvxFontListItem* pFontListItem = static_cast< const 
SvxFontListItem* >
-                    ( SfxObjectShell::Current()->GetItem( 
SID_ATTR_CHAR_FONTLIST ) );
+                    (pObjSh ? pObjSh->GetItem(SID_ATTR_CHAR_FONTLIST) : 
nullptr);
             const FontList* pFontList = pFontListItem ? 
pFontListItem->GetFontList() : nullptr;
             pOLV->GetEditView().ChangeFontSize( nSlot == FN_GROW_FONT_SIZE, 
pFontList );
         }
diff --git a/sw/source/uibase/sidebar/PageStylesPanel.cxx 
b/sw/source/uibase/sidebar/PageStylesPanel.cxx
index ca481345d581..1956b414a951 100644
--- a/sw/source/uibase/sidebar/PageStylesPanel.cxx
+++ b/sw/source/uibase/sidebar/PageStylesPanel.cxx
@@ -260,11 +260,14 @@ XGradient const & 
PageStylesPanel::GetGradientSetOrDefault()
 {
     if( !mpBgGradientItem )
     {
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-        const SvxGradientListItem * pGradListItem = 
pSh->GetItem(SID_GRADIENT_LIST);
-        const XGradient aGradient = 
pGradListItem->GetGradientList()->GetGradient(0)->GetGradient();
-        const OUString aGradientName = 
pGradListItem->GetGradientList()->GetGradient(0)->GetName();
-
+        XGradient aGradient;
+        OUString aGradientName;
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
+        {
+            const SvxGradientListItem* pGradListItem = 
pSh->GetItem(SID_GRADIENT_LIST);
+            aGradient = 
pGradListItem->GetGradientList()->GetGradient(0)->GetGradient();
+            aGradientName = 
pGradListItem->GetGradientList()->GetGradient(0)->GetName();
+        }
         mpBgGradientItem.reset( new XFillGradientItem( aGradientName, 
aGradient ) );
     }
 
@@ -275,11 +278,14 @@ OUString const & 
PageStylesPanel::GetHatchingSetOrDefault()
 {
     if( !mpBgHatchItem )
     {
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-        const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST);
-        const XHatch aHatch = 
pHatchListItem->GetHatchList()->GetHatch(0)->GetHatch();
-        const OUString aHatchName = 
pHatchListItem->GetHatchList()->GetHatch(0)->GetName();
-
+        XHatch aHatch;
+        OUString aHatchName;
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
+        {
+            const SvxHatchListItem * pHatchListItem = 
pSh->GetItem(SID_HATCH_LIST);
+            aHatch = pHatchListItem->GetHatchList()->GetHatch(0)->GetHatch();
+            aHatchName = 
pHatchListItem->GetHatchList()->GetHatch(0)->GetName();
+        }
         mpBgHatchItem.reset( new XFillHatchItem( aHatchName, aHatch ) );
     }
 
@@ -290,11 +296,14 @@ OUString const & PageStylesPanel::GetBitmapSetOrDefault()
 {
     if( !mpBgBitmapItem || mpBgBitmapItem->isPattern() )
     {
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-        const SvxBitmapListItem * pBmpListItem = pSh->GetItem(SID_BITMAP_LIST);
-        const GraphicObject aGraphObj = 
pBmpListItem->GetBitmapList()->GetBitmap(0)->GetGraphicObject();
-        const OUString aBmpName = 
pBmpListItem->GetBitmapList()->GetBitmap(0)->GetName();
-
+        GraphicObject aGraphObj;
+        OUString aBmpName;
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
+        {
+            const SvxBitmapListItem * pBmpListItem = 
pSh->GetItem(SID_BITMAP_LIST);
+            aGraphObj = 
pBmpListItem->GetBitmapList()->GetBitmap(0)->GetGraphicObject();
+            aBmpName = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetName();
+        }
         mpBgBitmapItem.reset( new XFillBitmapItem( aBmpName, aGraphObj ) );
     }
 
@@ -305,11 +314,14 @@ OUString const & PageStylesPanel::GetPatternSetOrDefault()
 {
     if( !mpBgBitmapItem || !mpBgBitmapItem->isPattern() )
     {
-        SfxObjectShell* pSh = SfxObjectShell::Current();
-        const SvxPatternListItem * pPatternListItem = 
pSh->GetItem(SID_PATTERN_LIST);
-        const GraphicObject aGraphObj = 
pPatternListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject();
-        const OUString aPatternName = 
pPatternListItem->GetPatternList()->GetBitmap(0)->GetName();
-
+        GraphicObject aGraphObj;
+        OUString aPatternName;
+        if (SfxObjectShell* pSh = SfxObjectShell::Current())
+        {
+            const SvxPatternListItem * pPatternListItem = 
pSh->GetItem(SID_PATTERN_LIST);
+            aGraphObj = 
pPatternListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject();
+            aPatternName = 
pPatternListItem->GetPatternList()->GetBitmap(0)->GetName();
+        }
         mpBgBitmapItem.reset( new XFillBitmapItem( aPatternName, aGraphObj ) );
     }
 
@@ -547,40 +559,42 @@ void PageStylesPanel::ModifyFillColor()
         }
         break;
         case HATCH:
-        {
-            const SvxHatchListItem * pHatchListItem = 
pSh->GetItem(SID_HATCH_LIST);
-            sal_uInt16 nPos = mxBgHatchingLB->get_active();
-            XHatch aHatch = 
pHatchListItem->GetHatchList()->GetHatch(nPos)->GetHatch();
-            const OUString aHatchName = 
pHatchListItem->GetHatchList()->GetHatch(nPos)->GetName();
+            if (pSh)
+            {
+                const SvxHatchListItem * pHatchListItem = 
pSh->GetItem(SID_HATCH_LIST);
+                sal_uInt16 nPos = mxBgHatchingLB->get_active();
+                XHatch aHatch = 
pHatchListItem->GetHatchList()->GetHatch(nPos)->GetHatch();
+                const OUString aHatchName = 
pHatchListItem->GetHatchList()->GetHatch(nPos)->GetName();
 
-            XFillHatchItem aItem(aHatchName, aHatch);
-            GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH, 
SfxCallMode::RECORD, { &aItem });
-        }
-        break;
+                XFillHatchItem aItem(aHatchName, aHatch);
+                
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH, 
SfxCallMode::RECORD, { &aItem });
+            }
+            break;
         case BITMAP:
         case PATTERN:
-        {
-            sal_Int16 nPos = mxBgBitmapLB->get_active();
-            GraphicObject aBitmap;
-            OUString aBitmapName;
-
-            if ( eXFS == BITMAP )
-            {
-                SvxBitmapListItem const * pBitmapListItem = 
pSh->GetItem(SID_BITMAP_LIST);
-                aBitmap = 
pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetGraphicObject();
-                aBitmapName = 
pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetName();
-            }
-            else
+            if (pSh)
             {
-                SvxPatternListItem const * pPatternListItem = 
pSh->GetItem(SID_PATTERN_LIST);
-                aBitmap = 
pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetGraphicObject();
-                aBitmapName = 
pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetName();
-            }
+                sal_Int16 nPos = mxBgBitmapLB->get_active();
+                GraphicObject aBitmap;
+                OUString aBitmapName;
 
-            XFillBitmapItem aItem(aBitmapName, aBitmap);
-            GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP, 
SfxCallMode::RECORD, { &aItem });
-        }
-        break;
+                if ( eXFS == BITMAP )
+                {
+                    SvxBitmapListItem const * pBitmapListItem = 
pSh->GetItem(SID_BITMAP_LIST);
+                    aBitmap = 
pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetGraphicObject();
+                    aBitmapName = 
pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetName();
+                }
+                else
+                {
+                    SvxPatternListItem const * pPatternListItem = 
pSh->GetItem(SID_PATTERN_LIST);
+                    aBitmap = 
pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetGraphicObject();
+                    aBitmapName = 
pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetName();
+                }
+
+                XFillBitmapItem aItem(aBitmapName, aBitmap);
+                
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP, 
SfxCallMode::RECORD, { &aItem });
+            }
+            break;
         default:
             break;
     }
diff --git a/sw/source/uibase/sidebar/StylePresetsPanel.cxx 
b/sw/source/uibase/sidebar/StylePresetsPanel.cxx
index 981f26b3e839..ef6b740bd7e8 100644
--- a/sw/source/uibase/sidebar/StylePresetsPanel.cxx
+++ b/sw/source/uibase/sidebar/StylePresetsPanel.cxx
@@ -118,13 +118,13 @@ BitmapEx GenerateStylePreview(SfxObjectShell& rSource, 
OUString const & aName)
 
 BitmapEx CreatePreview(OUString const & aUrl, OUString const & aName)
 {
-    SfxMedium aMedium(aUrl, StreamMode::STD_READWRITE);
-    SfxObjectShell* pObjectShell = SfxObjectShell::Current();
-    SfxObjectShellLock xTemplDoc = 
SfxObjectShell::CreateObjectByFactoryName(pObjectShell->GetFactory().GetFactoryName(),
 SfxObjectCreateMode::ORGANIZER);
-    xTemplDoc->DoInitNew();
-    if (xTemplDoc->LoadFrom(aMedium))
+    if (SfxObjectShell* pObjectShell = SfxObjectShell::Current())
     {
-        return GenerateStylePreview(*xTemplDoc, aName);
+        SfxMedium aMedium(aUrl, StreamMode::STD_READWRITE);
+        SfxObjectShellLock xTemplDoc = 
SfxObjectShell::CreateObjectByFactoryName(pObjectShell->GetFactory().GetFactoryName(),
 SfxObjectCreateMode::ORGANIZER);
+        xTemplDoc->DoInitNew();
+        if (xTemplDoc->LoadFrom(aMedium))
+            return GenerateStylePreview(*xTemplDoc, aName);
     }
     return BitmapEx();
 }
@@ -185,8 +185,7 @@ IMPL_LINK_NOARG(StylePresetsPanel, DoubleClickHdl, 
ValueSet*, void)
     sal_Int32 nItemId = mxValueSet->GetSelectedItemId();
     TemplateEntry* pEntry = 
static_cast<TemplateEntry*>(mxValueSet->GetItemData(nItemId));
 
-    SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
-    if (pDocSh)
+    if (SwDocShell* pDocSh = 
static_cast<SwDocShell*>(SfxObjectShell::Current()))
     {
         SwgReaderOption aOption;
         aOption.SetTextFormats(true);
diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx 
b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
index d7772596df70..518b61d8f1a1 100644
--- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
+++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
@@ -419,15 +419,17 @@ static void MetadataToTreeNode(const 
css::uno::Reference<css::uno::XInterface>&
 
     // list associated (predicate, object) pairs of the actual subject
     // under the tree node "Metadata Reference"
-    SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
-    uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(pDocSh->GetBaseModel(),
-                                                                         
uno::UNO_QUERY);
-    const uno::Reference<rdf::XRepository>& xRepo = 
xDocumentMetadataAccess->getRDFRepository();
-    const css::uno::Reference<css::rdf::XResource> xSubject(rSource, 
uno::UNO_QUERY);
-    std::map<OUString, OUString> xStatements
-        = SwRDFHelper::getStatements(pDocSh->GetBaseModel(), 
xRepo->getGraphNames(), xSubject);
-    for (const auto& pair : xStatements)
-        aCurNode.children.push_back(SimplePropToTreeNode(pair.first, 
uno::Any(pair.second)));
+    if (SwDocShell* pDocSh = 
static_cast<SwDocShell*>(SfxObjectShell::Current()))
+    {
+        uno::Reference<rdf::XDocumentMetadataAccess> 
xDocumentMetadataAccess(pDocSh->GetBaseModel(),
+                                                                             
uno::UNO_QUERY);
+        const uno::Reference<rdf::XRepository>& xRepo = 
xDocumentMetadataAccess->getRDFRepository();
+        const css::uno::Reference<css::rdf::XResource> xSubject(rSource, 
uno::UNO_QUERY);
+        std::map<OUString, OUString> xStatements
+            = SwRDFHelper::getStatements(pDocSh->GetBaseModel(), 
xRepo->getGraphNames(), xSubject);
+        for (const auto& pair : xStatements)
+            aCurNode.children.push_back(SimplePropToTreeNode(pair.first, 
uno::Any(pair.second)));
+    }
 
     rNode.children.push_back(aCurNode);
 }

Reply via email to