[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - linguistic/source

Stephan Bergmann sbergman at redhat.com
Thu Jan 22 05:02:49 PST 2015


 linguistic/source/gciterator.cxx |  110 +++++++++++++++++++++------------------
 1 file changed, 60 insertions(+), 50 deletions(-)

New commits:
commit 2a3f9f7b4583f440ee18fda6638f742af8667312
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jan 22 12:47:29 2015 +0100

    rhbz#1184582: At least catch and log UNO exceptions in grammar checking thread
    
    (cherry picked from commit b1dbc511eeaf88e3b4b5a8a2dce129d251d2dcb6)
    Conflicts:
    	linguistic/source/gciterator.cxx
    
    Change-Id: I87744f86d1413973709a46a58ebc03a39bce842c
    Reviewed-on: https://gerrit.libreoffice.org/14101
    Tested-by: Michael Stahl <mstahl at redhat.com>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx
index 74f9aba..35c8875 100644
--- a/linguistic/source/gciterator.cxx
+++ b/linguistic/source/gciterator.cxx
@@ -543,70 +543,80 @@ void GrammarCheckingIterator::DequeueAndCheck()
 
             if (xFlatPara.is() && xFPIterator.is())
             {
-                OUString aCurTxt( xFlatPara->getText() );
-                lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex );
-
-                bModified = xFlatPara->isModified();
-                if (!bModified)
+                try
                 {
-                    // ---- THREAD SAFE START ----
-                    ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() );
+                    OUString aCurTxt( xFlatPara->getText() );
+                    lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex );
 
-                    sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex;
-                    sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale );
-                    DBG_ASSERT( (nSuggestedEnd == 0 && aCurTxt.isEmpty()) || nSuggestedEnd > nStartPos,
-                            "nSuggestedEndOfSentencePos calculation failed?" );
+                    bModified = xFlatPara->isModified();
+                    if (!bModified)
+                    {
+                        // ---- THREAD SAFE START ----
+                        ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() );
 
-                    linguistic2::ProofreadingResult aRes;
+                        sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex;
+                        sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale );
+                        DBG_ASSERT( (nSuggestedEnd == 0 && aCurTxt.isEmpty()) || nSuggestedEnd > nStartPos,
+                                    "nSuggestedEndOfSentencePos calculation failed?" );
 
-                    uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY );
-                    if (xGC.is())
-                    {
-                        aGuard.clear();
-                        uno::Sequence<beans::PropertyValue> const aProps(
+                        linguistic2::ProofreadingResult aRes;
+
+                        uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY );
+                        if (xGC.is())
+                        {
+                            aGuard.clear();
+                            uno::Sequence<beans::PropertyValue> const aProps(
                                 lcl_makeProperties(xFlatPara));
-                        aRes = xGC->doProofreading( aCurDocId, aCurTxt,
-                                aCurLocale, nStartPos, nSuggestedEnd, aProps );
-
-                        //!! work-around to prevent looping if the grammar checker
-                        //!! failed to properly identify the sentence end
-                        if (
-                            aRes.nBehindEndOfSentencePosition <= nStartPos &&
-                            aRes.nBehindEndOfSentencePosition != nSuggestedEnd
-                           )
+                            aRes = xGC->doProofreading( aCurDocId, aCurTxt,
+                                                        aCurLocale, nStartPos, nSuggestedEnd, aProps );
+
+                            //!! work-around to prevent looping if the grammar checker
+                            //!! failed to properly identify the sentence end
+                            if (
+                                aRes.nBehindEndOfSentencePosition <= nStartPos &&
+                                aRes.nBehindEndOfSentencePosition != nSuggestedEnd
+                            )
+                            {
+                                DBG_ASSERT( false, "!! Grammarchecker failed to provide end of sentence !!" );
+                                aRes.nBehindEndOfSentencePosition = nSuggestedEnd;
+                            }
+
+                            aRes.xFlatParagraph      = xFlatPara;
+                            aRes.nStartOfSentencePosition = nStartPos;
+                        }
+                        else
                         {
-                            DBG_ASSERT( false, "!! Grammarchecker failed to provide end of sentence !!" );
-                            aRes.nBehindEndOfSentencePosition = nSuggestedEnd;
+                            // no grammar checker -> no error
+                            // but we need to provide the data below in order to continue with the next sentence
+                            aRes.aDocumentIdentifier = aCurDocId;
+                            aRes.xFlatParagraph      = xFlatPara;
+                            aRes.aText               = aCurTxt;
+                            aRes.aLocale             = aCurLocale;
+                            aRes.nStartOfSentencePosition       = nStartPos;
+                            aRes.nBehindEndOfSentencePosition   = nSuggestedEnd;
                         }
+                        aRes.nStartOfNextSentencePosition = lcl_SkipWhiteSpaces( aCurTxt, aRes.nBehindEndOfSentencePosition );
+                        aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( aCurTxt, aRes.nStartOfNextSentencePosition );
 
-                        aRes.xFlatParagraph      = xFlatPara;
-                        aRes.nStartOfSentencePosition = nStartPos;
+                        //guard has to be cleared as ProcessResult calls out of this class
+                        aGuard.clear();
+                        ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic );
+                        // ---- THREAD SAFE END ----
                     }
                     else
                     {
-                        // no grammar checker -> no error
-                        // but we need to provide the data below in order to continue with the next sentence
-                        aRes.aDocumentIdentifier = aCurDocId;
-                        aRes.xFlatParagraph      = xFlatPara;
-                        aRes.aText               = aCurTxt;
-                        aRes.aLocale             = aCurLocale;
-                        aRes.nStartOfSentencePosition       = nStartPos;
-                        aRes.nBehindEndOfSentencePosition   = nSuggestedEnd;
+                        // the paragraph changed meanwhile... (and maybe is still edited)
+                        // thus we simply continue to ask for the next to be checked.
+                        uno::Reference< text::XFlatParagraph > xFlatParaNext( xFPIterator->getNextPara() );
+                        AddEntry( xFPIterator, xFlatParaNext, aCurDocId, 0, aFPEntryItem.m_bAutomatic );
                     }
-                    aRes.nStartOfNextSentencePosition = lcl_SkipWhiteSpaces( aCurTxt, aRes.nBehindEndOfSentencePosition );
-                    aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( aCurTxt, aRes.nStartOfNextSentencePosition );
-
-                    //guard has to be cleared as ProcessResult calls out of this class
-                    aGuard.clear();
-                    ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic );
-                    // ---- THREAD SAFE END ----
                 }
-                else
+                catch (css::uno::Exception & e)
                 {
-                    // the paragraph changed meanwhile... (and maybe is still edited)
-                    // thus we simply continue to ask for the next to be checked.
-                    uno::Reference< text::XFlatParagraph > xFlatParaNext( xFPIterator->getNextPara() );
-                    AddEntry( xFPIterator, xFlatParaNext, aCurDocId, 0, aFPEntryItem.m_bAutomatic );
+                    SAL_WARN(
+                        "linguistic",
+                        "GrammarCheckingIterator::DequeueAndCheck ignoring UNO"
+                            " exception " << e.Message);
                 }
             }
 


More information about the Libreoffice-commits mailing list