XUnoTunnel->dynamic_cast in SwXTextRange

Change-Id: I87e635f371278132be9da4e6a60ba90180d25522
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145857
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/sw/inc/unotextrange.hxx b/sw/inc/unotextrange.hxx
index b64712b..a234d10 100644
--- a/sw/inc/unotextrange.hxx
+++ b/sw/inc/unotextrange.hxx
@@ -20,7 +20,6 @@
#ifndef INCLUDED_SW_INC_UNOTEXTRANGE_HXX
#define INCLUDED_SW_INC_UNOTEXTRANGE_HXX

#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/XPropertyState.hpp>
@@ -76,8 +75,7 @@ namespace sw {
} // namespace sw

typedef ::cppu::WeakImplHelper
<   css::lang::XUnoTunnel
,   css::lang::XServiceInfo
<   css::lang::XServiceInfo
,   css::beans::XPropertySet
,   css::beans::XPropertyState
,   css::container::XEnumerationAccess
@@ -133,12 +131,6 @@ public:
            SwDoc & rDoc,
            const SwPosition& rPos, const SwPosition *const pMark);

    static const css::uno::Sequence< sal_Int8 >& getUnoTunnelId();

    // XUnoTunnel
    virtual sal_Int64 SAL_CALL getSomething(
            const css::uno::Sequence< sal_Int8 >& rIdentifier) override;

    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName() override;
    virtual sal_Bool SAL_CALL supportsService(
diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx
index 6faab28..7eb1f4d 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -214,9 +214,7 @@ void SwXBookmark::attachToRangeEx(
        throw uno::RuntimeException();
    }

    const uno::Reference<lang::XUnoTunnel> xRangeTunnel(
            xTextRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());

    SwDoc *const pDoc =
diff --git a/sw/source/core/unocore/unocontentcontrol.cxx b/sw/source/core/unocore/unocontentcontrol.cxx
index 6d07645..ceb7a29 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -437,8 +437,7 @@ void SwXContentControl::AttachImpl(const uno::Reference<text::XTextRange>& xText
                                    static_cast<::cppu::OWeakObject*>(this));
    }

    uno::Reference<lang::XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper* pCursor
        = pRange ? nullptr : dynamic_cast<OTextCursorHelper*>(xTextRange.get());
    if (!pRange && !pCursor)
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index a11dff3..add34e2 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -1987,7 +1987,7 @@ void SwXShape::attach(const uno::Reference< text::XTextRange > & xTextRange)
    // (see also SwXTextRange::XTextRangeToSwPaM)
    const SwDoc* pDoc = nullptr;
    uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
    if (auto pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel))
    if (auto pRange = dynamic_cast<SwXTextRange*>(xTextRange.get()))
        pDoc = &pRange->GetDoc();
    else if (auto pText = dynamic_cast<SwXText*>(xTextRange.get()))
        pDoc = pText->GetDoc();
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index abbde27..ffb0fa8 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -1350,8 +1350,7 @@ void SAL_CALL SwXTextField::attach(
    SolarMutexGuard aGuard;
    if (m_pImpl->IsDescriptor())
    {
        uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
        SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
        SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
        OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());

        SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor ? pCursor->GetDoc() : nullptr;
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index b81ba90..908f85a 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2724,8 +2724,7 @@ void SwXFrame::attachToRange(uno::Reference<text::XTextRange> const& xTextRange,
    SolarMutexGuard aGuard;
    if(!IsDescriptor())
        throw uno::RuntimeException();
    uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());

    SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor ? pCursor->GetDoc() : nullptr;
diff --git a/sw/source/core/unocore/unoftn.cxx b/sw/source/core/unocore/unoftn.cxx
index f27b8aa..c4ff75f 100644
--- a/sw/source/core/unocore/unoftn.cxx
+++ b/sw/source/core/unocore/unoftn.cxx
@@ -278,12 +278,8 @@ SwXFootnote::attach(const uno::Reference< text::XTextRange > & xTextRange)
    {
        throw uno::RuntimeException();
    }
    const uno::Reference<lang::XUnoTunnel> xRangeTunnel(
            xTextRange, uno::UNO_QUERY);
    SwXTextRange *const pRange =
        comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    OTextCursorHelper *const pCursor =
        dynamic_cast<OTextCursorHelper*>(xTextRange.get());
    SwXTextRange *const pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper *const pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());
    SwDoc *const pNewDoc =
        pRange ? &pRange->GetDoc() : (pCursor ? pCursor->GetDoc() : nullptr);
    if (!pNewDoc)
diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index c032270..736f252 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -1288,9 +1288,7 @@ SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange)
    {
        throw uno::RuntimeException();
    }
    const uno::Reference<XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
    SwXTextRange *const pRange =
        comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange *const pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper *const pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());

    SwDoc *const pDoc =
@@ -1756,9 +1754,8 @@ SwXDocumentIndexMark::attach(
        throw uno::RuntimeException();
    }

    const uno::Reference<XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY);
    SwXTextRange *const pRange =
        comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
        dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper *const pCursor =
        dynamic_cast<OTextCursorHelper*>(xTextRange.get());
    SwDoc *const pDoc =
diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx
index 4d50250..7ef11b9 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -1192,8 +1192,7 @@ SwXTextCursor::gotoRange(

    SwUnoCursor & rOwnCursor( GetCursorOrThrow() );

    uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xRange.get());
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xRange.get());

    if (!pRange && !pCursor)
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index 75461d2..6983704 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -901,19 +901,6 @@ void SwXTextRange::DeleteAndInsert(
    m_pImpl->m_rDoc.GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
}

const uno::Sequence< sal_Int8 > & SwXTextRange::getUnoTunnelId()
{
    static const comphelper::UnoIdInit theSwXTextRangeUnoTunnelId;
    return theSwXTextRangeUnoTunnelId.getSeq();
}

// XUnoTunnel
sal_Int64 SAL_CALL
SwXTextRange::getSomething(const uno::Sequence< sal_Int8 >& rId)
{
    return comphelper::getSomethingImpl<SwXTextRange>(rId, this);
}

OUString SAL_CALL
SwXTextRange::getImplementationName()
{
@@ -1107,7 +1094,7 @@ bool XTextRangeToSwPaM( SwUnoInternalPaM & rToFill,
    bool bRet = false;

    uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());
    SwXTextPortion* pPortion = comphelper::getFromUnoTunnel<SwXTextPortion>(xRangeTunnel);
    SwXText* pText = dynamic_cast<SwXText*>(xTextRange.get());
diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx
index 623710f..d2af2e8 100644
--- a/sw/source/core/unocore/unorefmk.cxx
+++ b/sw/source/core/unocore/unorefmk.cxx
@@ -270,8 +270,7 @@ SwXReferenceMark::attach(const uno::Reference< text::XTextRange > & xTextRange)
    {
        throw uno::RuntimeException();
    }
    uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());
    SwDoc *const pDocument =
        pRange ? &pRange->GetDoc() : (pCursor ? pCursor->GetDoc() : nullptr);
@@ -936,9 +935,7 @@ SwXMeta::AttachImpl(const uno::Reference< text::XTextRange > & i_xTextRange,
            static_cast< ::cppu::OWeakObject* >(this));
    }

    uno::Reference<lang::XUnoTunnel> xRangeTunnel(i_xTextRange, uno::UNO_QUERY);
    SwXTextRange *const pRange(
            comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel));
    SwXTextRange *const pRange(dynamic_cast<SwXTextRange*>(i_xTextRange.get()));
    OTextCursorHelper *const pCursor(dynamic_cast<OTextCursorHelper*>(i_xTextRange.get()));
    if (!pRange && !pCursor)
    {
diff --git a/sw/source/core/unocore/unosect.cxx b/sw/source/core/unocore/unosect.cxx
index 990c561..5bb3ff0 100644
--- a/sw/source/core/unocore/unosect.cxx
+++ b/sw/source/core/unocore/unosect.cxx
@@ -279,8 +279,7 @@ SwXTextSection::attach(const uno::Reference< text::XTextRange > & xTextRange)
        throw uno::RuntimeException();
    }

    uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());

    SwDoc *const pDoc =
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index 0aaedfa..acf4112 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -2060,8 +2060,7 @@ SwXTextTable::attach(const uno::Reference<text::XTextRange> & xTextRange)
    if (!m_pImpl->IsDescriptor())  /* already attached ? */
        throw uno::RuntimeException("SwXTextTable: already attached to range.", static_cast<cppu::OWeakObject*>(this));

    uno::Reference<lang::XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY);
    SwXTextRange* pRange(comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel));
    SwXTextRange* pRange(dynamic_cast<SwXTextRange*>(xTextRange.get()));
    OTextCursorHelper* pCursor(dynamic_cast<OTextCursorHelper*>(xTextRange.get()));
    SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor ? pCursor->GetDoc() : nullptr;
    if (!pDoc || !m_pImpl->m_nRows || !m_pImpl->m_nColumns)
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 52df529..7193fe3 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -293,10 +293,7 @@ SwXText::insertString(const uno::Reference< text::XTextRange >& xTextRange,
    {
        throw uno::RuntimeException();
    }
    const uno::Reference<lang::XUnoTunnel> xRangeTunnel(xTextRange,
            uno::UNO_QUERY);
    SwXTextRange *const pRange =
        comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange *const pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper *const pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());
    if ((!pRange  || &pRange ->GetDoc() != GetDoc()) &&
        (!pCursor || pCursor->GetDoc() != GetDoc()))
@@ -432,10 +429,8 @@ SwXText::insertControlCharacter(
            m_pImpl->m_pDoc->ClearBoxNumAttrs(aPam.GetPoint()->GetNode());
            m_pImpl->m_pDoc->getIDocumentContentOperations().AppendTextNode(*aPam.GetPoint());

            const uno::Reference<lang::XUnoTunnel> xRangeTunnel(
                    xTextRange, uno::UNO_QUERY);
            SwXTextRange *const pRange =
                comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
                dynamic_cast<SwXTextRange*>(xTextRange.get());
            OTextCursorHelper *const pCursor =
                dynamic_cast<OTextCursorHelper*>(xTextRange.get());
            if (pRange)
@@ -464,10 +459,8 @@ SwXText::insertControlCharacter(
    if (!bAbsorb)
        return;

    const uno::Reference<lang::XUnoTunnel> xRangeTunnel(
            xTextRange, uno::UNO_QUERY);
    SwXTextRange *const pRange =
        comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
        dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper *const pCursor =
        dynamic_cast<OTextCursorHelper*>(xTextRange.get());

@@ -596,8 +589,7 @@ SwXText::insertTextContent(

    if (bAbsorb && !bAttribute)
    {
        uno::Reference<lang::XUnoTunnel> const xRangeTunnel(xRange, uno::UNO_QUERY);
        if (SwXTextRange *const pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel))
        if (SwXTextRange *const pRange = dynamic_cast<SwXTextRange*>(xRange.get()))
        {
            pRange->DeleteAndInsert(u"", ::sw::DeleteAndInsertMode::ForceReplace
                | (bForceExpandHints ? ::sw::DeleteAndInsertMode::ForceExpandHints : ::sw::DeleteAndInsertMode::Default));
@@ -1550,10 +1542,8 @@ SwXText::convertToTextFrame(
    }
    pTempStartPam.reset();

    SwXTextRange *const pStartRange =
        comphelper::getFromUnoTunnel<SwXTextRange>(xStart);
    SwXTextRange *const pEndRange   =
        comphelper::getFromUnoTunnel<SwXTextRange>(xEnd);
    SwXTextRange *const pStartRange = dynamic_cast<SwXTextRange*>(xStart.get());
    SwXTextRange *const pEndRange   = dynamic_cast<SwXTextRange*>(xEnd.get());
    // bookmarks have to be removed before the referenced text node
    // is deleted in DelFullPara
    if (pStartRange)
diff --git a/sw/source/core/unocore/unotextmarkup.cxx b/sw/source/core/unocore/unotextmarkup.cxx
index 2aa8aef..4bbc860 100644
--- a/sw/source/core/unocore/unotextmarkup.cxx
+++ b/sw/source/core/unocore/unotextmarkup.cxx
@@ -99,9 +99,7 @@ void SAL_CALL SwXTextMarkup::commitTextRangeMarkup(::sal_Int32 nType, const OUSt
{
    SolarMutexGuard aGuard;

    uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);

    if (auto pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel))
    if (auto pRange = dynamic_cast<SwXTextRange*>(xRange.get()))
    {
        SwDoc& rDoc = pRange->GetDoc();

diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
index d5848ea..a78a7e4 100644
--- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx
+++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
@@ -68,10 +68,8 @@ static SwDoc* lcl_GetDocViaTunnel( Reference<XTextCursor> const & rCursor )

static SwDoc* lcl_GetDocViaTunnel( Reference<XTextRange> const & rRange )
{
    Reference<XUnoTunnel> xTunnel(rRange, UNO_QUERY);
    OSL_ENSURE(xTunnel.is(), "missing XUnoTunnel for XTextRange");
    SwXTextRange *const pXRange =
        comphelper::getFromUnoTunnel<SwXTextRange>(xTunnel);
    SwXTextRange *const pXRange = dynamic_cast<SwXTextRange*>(rRange.get());
    OSL_ENSURE(pXRange, "missing SwXTextRange for XTextRange");
    // #i115174#: this may be a SvxUnoTextRange
    // OSL_ENSURE( pXRange, "SwXTextRange missing" );
    return pXRange ? &pXRange->GetDoc() : nullptr;
diff --git a/sw/source/uibase/uno/unoatxt.cxx b/sw/source/uibase/uno/unoatxt.cxx
index f1358df..a396042 100644
--- a/sw/source/uibase/uno/unoatxt.cxx
+++ b/sw/source/uibase/uno/unoatxt.cxx
@@ -329,8 +329,7 @@ uno::Reference< text::XAutoTextEntry >  SwXAutoTextGroup::insertNewByName(const 
    const OUString& sLongName(aTitle);
    if (pGlosGroup && !pGlosGroup->GetError())
    {
        uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
        SwXTextRange* pxRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
        SwXTextRange* pxRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
        OTextCursorHelper* pxCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());

        OUString sOnlyText;
@@ -850,10 +849,9 @@ void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextR

    // The reference to xKeepAlive is needed during the whole call, likely because it could be a
    // different object, not xTextRange itself, and the reference guards it from preliminary death
    uno::Reference<text::XTextRange> xKeepAlive( xTextRange );
    uno::Reference<lang::XUnoTunnel> xTunnel( xTextRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xTunnel);
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xKeepAlive.get());
    auto xKeepAlive( xTextRange );
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xTextRange.get());
    SwXText *pText = dynamic_cast<SwXText*>(xTextRange.get());

    SwDoc* pDoc = nullptr;
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index b19827e..abc6fb9 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -787,8 +787,7 @@ SwUnoCursor* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor >
        }
        else
        {
            Reference<XUnoTunnel> xCursorTunnel( xLastResult, UNO_QUERY);
            SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xCursorTunnel);
            SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xLastResult.get());
            if(!pRange)
                return nullptr;
            pRange->GetPositions(*pUnoCursor);
diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx
index 953b430..ec07edb 100644
--- a/sw/source/uibase/uno/unotxvw.cxx
+++ b/sw/source/uibase/uno/unotxvw.cxx
@@ -988,8 +988,7 @@ void SwXTextViewCursor::gotoRange(
        *aOwnPaM.GetMark() = *pShellCursor->GetMark();
    }

    uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);
    SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xRangeTunnel);
    SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xRange.get());
    SwXParagraph* pPara = dynamic_cast<SwXParagraph*>(xRange.get());
    OTextCursorHelper* pCursor = dynamic_cast<OTextCursorHelper*>(xRange.get());