9dff008
From d7548760e51941dad67389b21e943a968b37ba7c Mon Sep 17 00:00:00 2001
9dff008
From: Stephan Bergmann <sbergman@redhat.com>
9dff008
Date: Thu, 22 Jan 2015 12:47:29 +0100
9dff008
Subject: [PATCH] rhbz#1184582: At least catch and log UNO exceptions in
9dff008
 grammar checking thread
9dff008
9dff008
(cherry picked from commit b1dbc511eeaf88e3b4b5a8a2dce129d251d2dcb6)
9dff008
Conflicts:
9dff008
	linguistic/source/gciterator.cxx
9dff008
9dff008
Change-Id: I87744f86d1413973709a46a58ebc03a39bce842c
9dff008
---
9dff008
 linguistic/source/gciterator.cxx | 110 +++++++++++++++++++++------------------
9dff008
 1 file changed, 60 insertions(+), 50 deletions(-)
9dff008
9dff008
diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx
9dff008
index 74f9aba..35c8875 100644
9dff008
--- a/linguistic/source/gciterator.cxx
9dff008
+++ b/linguistic/source/gciterator.cxx
9dff008
@@ -543,70 +543,80 @@ void GrammarCheckingIterator::DequeueAndCheck()
9dff008
 
9dff008
             if (xFlatPara.is() && xFPIterator.is())
9dff008
             {
9dff008
-                OUString aCurTxt( xFlatPara->getText() );
9dff008
-                lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex );
9dff008
-
9dff008
-                bModified = xFlatPara->isModified();
9dff008
-                if (!bModified)
9dff008
+                try
9dff008
                 {
9dff008
-                    // ---- THREAD SAFE START ----
9dff008
-                    ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() );
9dff008
+                    OUString aCurTxt( xFlatPara->getText() );
9dff008
+                    lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex );
9dff008
 
9dff008
-                    sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex;
9dff008
-                    sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale );
9dff008
-                    DBG_ASSERT( (nSuggestedEnd == 0 && aCurTxt.isEmpty()) || nSuggestedEnd > nStartPos,
9dff008
-                            "nSuggestedEndOfSentencePos calculation failed?" );
9dff008
+                    bModified = xFlatPara->isModified();
9dff008
+                    if (!bModified)
9dff008
+                    {
9dff008
+                        // ---- THREAD SAFE START ----
9dff008
+                        ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() );
9dff008
 
9dff008
-                    linguistic2::ProofreadingResult aRes;
9dff008
+                        sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex;
9dff008
+                        sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale );
9dff008
+                        DBG_ASSERT( (nSuggestedEnd == 0 && aCurTxt.isEmpty()) || nSuggestedEnd > nStartPos,
9dff008
+                                    "nSuggestedEndOfSentencePos calculation failed?" );
9dff008
 
9dff008
-                    uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY );
9dff008
-                    if (xGC.is())
9dff008
-                    {
9dff008
-                        aGuard.clear();
9dff008
-                        uno::Sequence<beans::PropertyValue> const aProps(
9dff008
+                        linguistic2::ProofreadingResult aRes;
9dff008
+
9dff008
+                        uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY );
9dff008
+                        if (xGC.is())
9dff008
+                        {
9dff008
+                            aGuard.clear();
9dff008
+                            uno::Sequence<beans::PropertyValue> const aProps(
9dff008
                                 lcl_makeProperties(xFlatPara));
9dff008
-                        aRes = xGC->doProofreading( aCurDocId, aCurTxt,
9dff008
-                                aCurLocale, nStartPos, nSuggestedEnd, aProps );
9dff008
-
9dff008
-                        //!! work-around to prevent looping if the grammar checker
9dff008
-                        //!! failed to properly identify the sentence end
9dff008
-                        if (
9dff008
-                            aRes.nBehindEndOfSentencePosition <= nStartPos &&
9dff008
-                            aRes.nBehindEndOfSentencePosition != nSuggestedEnd
9dff008
-                           )
9dff008
+                            aRes = xGC->doProofreading( aCurDocId, aCurTxt,
9dff008
+                                                        aCurLocale, nStartPos, nSuggestedEnd, aProps );
9dff008
+
9dff008
+                            //!! work-around to prevent looping if the grammar checker
9dff008
+                            //!! failed to properly identify the sentence end
9dff008
+                            if (
9dff008
+                                aRes.nBehindEndOfSentencePosition <= nStartPos &&
9dff008
+                                aRes.nBehindEndOfSentencePosition != nSuggestedEnd
9dff008
+                            )
9dff008
+                            {
9dff008
+                                DBG_ASSERT( false, "!! Grammarchecker failed to provide end of sentence !!" );
9dff008
+                                aRes.nBehindEndOfSentencePosition = nSuggestedEnd;
9dff008
+                            }
9dff008
+
9dff008
+                            aRes.xFlatParagraph      = xFlatPara;
9dff008
+                            aRes.nStartOfSentencePosition = nStartPos;
9dff008
+                        }
9dff008
+                        else
9dff008
                         {
9dff008
-                            DBG_ASSERT( false, "!! Grammarchecker failed to provide end of sentence !!" );
9dff008
-                            aRes.nBehindEndOfSentencePosition = nSuggestedEnd;
9dff008
+                            // no grammar checker -> no error
9dff008
+                            // but we need to provide the data below in order to continue with the next sentence
9dff008
+                            aRes.aDocumentIdentifier = aCurDocId;
9dff008
+                            aRes.xFlatParagraph      = xFlatPara;
9dff008
+                            aRes.aText               = aCurTxt;
9dff008
+                            aRes.aLocale             = aCurLocale;
9dff008
+                            aRes.nStartOfSentencePosition       = nStartPos;
9dff008
+                            aRes.nBehindEndOfSentencePosition   = nSuggestedEnd;
9dff008
                         }
9dff008
+                        aRes.nStartOfNextSentencePosition = lcl_SkipWhiteSpaces( aCurTxt, aRes.nBehindEndOfSentencePosition );
9dff008
+                        aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( aCurTxt, aRes.nStartOfNextSentencePosition );
9dff008
 
9dff008
-                        aRes.xFlatParagraph      = xFlatPara;
9dff008
-                        aRes.nStartOfSentencePosition = nStartPos;
9dff008
+                        //guard has to be cleared as ProcessResult calls out of this class
9dff008
+                        aGuard.clear();
9dff008
+                        ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic );
9dff008
+                        // ---- THREAD SAFE END ----
9dff008
                     }
9dff008
                     else
9dff008
                     {
9dff008
-                        // no grammar checker -> no error
9dff008
-                        // but we need to provide the data below in order to continue with the next sentence
9dff008
-                        aRes.aDocumentIdentifier = aCurDocId;
9dff008
-                        aRes.xFlatParagraph      = xFlatPara;
9dff008
-                        aRes.aText               = aCurTxt;
9dff008
-                        aRes.aLocale             = aCurLocale;
9dff008
-                        aRes.nStartOfSentencePosition       = nStartPos;
9dff008
-                        aRes.nBehindEndOfSentencePosition   = nSuggestedEnd;
9dff008
+                        // the paragraph changed meanwhile... (and maybe is still edited)
9dff008
+                        // thus we simply continue to ask for the next to be checked.
9dff008
+                        uno::Reference< text::XFlatParagraph > xFlatParaNext( xFPIterator->getNextPara() );
9dff008
+                        AddEntry( xFPIterator, xFlatParaNext, aCurDocId, 0, aFPEntryItem.m_bAutomatic );
9dff008
                     }
9dff008
-                    aRes.nStartOfNextSentencePosition = lcl_SkipWhiteSpaces( aCurTxt, aRes.nBehindEndOfSentencePosition );
9dff008
-                    aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( aCurTxt, aRes.nStartOfNextSentencePosition );
9dff008
-
9dff008
-                    //guard has to be cleared as ProcessResult calls out of this class
9dff008
-                    aGuard.clear();
9dff008
-                    ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic );
9dff008
-                    // ---- THREAD SAFE END ----
9dff008
                 }
9dff008
-                else
9dff008
+                catch (css::uno::Exception & e)
9dff008
                 {
9dff008
-                    // the paragraph changed meanwhile... (and maybe is still edited)
9dff008
-                    // thus we simply continue to ask for the next to be checked.
9dff008
-                    uno::Reference< text::XFlatParagraph > xFlatParaNext( xFPIterator->getNextPara() );
9dff008
-                    AddEntry( xFPIterator, xFlatParaNext, aCurDocId, 0, aFPEntryItem.m_bAutomatic );
9dff008
+                    SAL_WARN(
9dff008
+                        "linguistic",
9dff008
+                        "GrammarCheckingIterator::DequeueAndCheck ignoring UNO"
9dff008
+                            " exception " << e.Message);
9dff008
                 }
9dff008
             }
9dff008
 
9dff008
-- 
9dff008
1.9.3
9dff008