1 |
tv |
812201 |
From dae6572c54a952d9da94261852496dc72fe51d92 Mon Sep 17 00:00:00 2001 |
2 |
|
|
From: Stephan Bergmann <sbergman@redhat.com> |
3 |
|
|
Date: Thu, 22 Jan 2015 12:47:29 +0100 |
4 |
|
|
Subject: [PATCH] rhbz#1184582: At least catch and log UNO exceptions in |
5 |
|
|
grammar checking thread |
6 |
|
|
|
7 |
|
|
(cherry picked from commit b1dbc511eeaf88e3b4b5a8a2dce129d251d2dcb6) |
8 |
|
|
Conflicts: |
9 |
|
|
linguistic/source/gciterator.cxx |
10 |
|
|
|
11 |
|
|
Change-Id: I87744f86d1413973709a46a58ebc03a39bce842c |
12 |
|
|
--- |
13 |
|
|
linguistic/source/gciterator.cxx | 110 +++++++++++++++++++++------------------ |
14 |
|
|
1 file changed, 60 insertions(+), 50 deletions(-) |
15 |
|
|
|
16 |
|
|
diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx |
17 |
|
|
index 41018e3..d3759eb 100644 |
18 |
|
|
--- a/linguistic/source/gciterator.cxx |
19 |
|
|
+++ b/linguistic/source/gciterator.cxx |
20 |
|
|
@@ -545,70 +545,80 @@ void GrammarCheckingIterator::DequeueAndCheck() |
21 |
|
|
|
22 |
|
|
if (xFlatPara.is() && xFPIterator.is()) |
23 |
|
|
{ |
24 |
|
|
- OUString aCurTxt( xFlatPara->getText() ); |
25 |
|
|
- lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex ); |
26 |
|
|
- |
27 |
|
|
- bModified = xFlatPara->isModified(); |
28 |
|
|
- if (!bModified) |
29 |
|
|
+ try |
30 |
|
|
{ |
31 |
|
|
- // ---- THREAD SAFE START ---- |
32 |
|
|
- ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() ); |
33 |
|
|
+ OUString aCurTxt( xFlatPara->getText() ); |
34 |
|
|
+ lang::Locale aCurLocale = lcl_GetPrimaryLanguageOfSentence( xFlatPara, aFPEntryItem.m_nStartIndex ); |
35 |
|
|
|
36 |
|
|
- sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex; |
37 |
|
|
- sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale ); |
38 |
|
|
- DBG_ASSERT( (nSuggestedEnd == 0 && aCurTxt.isEmpty()) || nSuggestedEnd > nStartPos, |
39 |
|
|
- "nSuggestedEndOfSentencePos calculation failed?" ); |
40 |
|
|
+ bModified = xFlatPara->isModified(); |
41 |
|
|
+ if (!bModified) |
42 |
|
|
+ { |
43 |
|
|
+ // ---- THREAD SAFE START ---- |
44 |
|
|
+ ::osl::ClearableGuard< ::osl::Mutex > aGuard( MyMutex::get() ); |
45 |
|
|
|
46 |
|
|
- linguistic2::ProofreadingResult aRes; |
47 |
|
|
+ sal_Int32 nStartPos = aFPEntryItem.m_nStartIndex; |
48 |
|
|
+ sal_Int32 nSuggestedEnd = GetSuggestedEndOfSentence( aCurTxt, nStartPos, aCurLocale ); |
49 |
|
|
+ DBG_ASSERT( (nSuggestedEnd == 0 && aCurTxt.isEmpty()) || nSuggestedEnd > nStartPos, |
50 |
|
|
+ "nSuggestedEndOfSentencePos calculation failed?" ); |
51 |
|
|
|
52 |
|
|
- uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY ); |
53 |
|
|
- if (xGC.is()) |
54 |
|
|
- { |
55 |
|
|
- aGuard.clear(); |
56 |
|
|
- uno::Sequence<beans::PropertyValue> const aProps( |
57 |
|
|
+ linguistic2::ProofreadingResult aRes; |
58 |
|
|
+ |
59 |
|
|
+ uno::Reference< linguistic2::XProofreader > xGC( GetGrammarChecker( aCurLocale ), uno::UNO_QUERY ); |
60 |
|
|
+ if (xGC.is()) |
61 |
|
|
+ { |
62 |
|
|
+ aGuard.clear(); |
63 |
|
|
+ uno::Sequence<beans::PropertyValue> const aProps( |
64 |
|
|
lcl_makeProperties(xFlatPara)); |
65 |
|
|
- aRes = xGC->doProofreading( aCurDocId, aCurTxt, |
66 |
|
|
- aCurLocale, nStartPos, nSuggestedEnd, aProps ); |
67 |
|
|
- |
68 |
|
|
- //!! work-around to prevent looping if the grammar checker |
69 |
|
|
- //!! failed to properly identify the sentence end |
70 |
|
|
- if ( |
71 |
|
|
- aRes.nBehindEndOfSentencePosition <= nStartPos && |
72 |
|
|
- aRes.nBehindEndOfSentencePosition != nSuggestedEnd |
73 |
|
|
- ) |
74 |
|
|
+ aRes = xGC->doProofreading( aCurDocId, aCurTxt, |
75 |
|
|
+ aCurLocale, nStartPos, nSuggestedEnd, aProps ); |
76 |
|
|
+ |
77 |
|
|
+ //!! work-around to prevent looping if the grammar checker |
78 |
|
|
+ //!! failed to properly identify the sentence end |
79 |
|
|
+ if ( |
80 |
|
|
+ aRes.nBehindEndOfSentencePosition <= nStartPos && |
81 |
|
|
+ aRes.nBehindEndOfSentencePosition != nSuggestedEnd |
82 |
|
|
+ ) |
83 |
|
|
+ { |
84 |
|
|
+ DBG_ASSERT( false, "!! Grammarchecker failed to provide end of sentence !!" ); |
85 |
|
|
+ aRes.nBehindEndOfSentencePosition = nSuggestedEnd; |
86 |
|
|
+ } |
87 |
|
|
+ |
88 |
|
|
+ aRes.xFlatParagraph = xFlatPara; |
89 |
|
|
+ aRes.nStartOfSentencePosition = nStartPos; |
90 |
|
|
+ } |
91 |
|
|
+ else |
92 |
|
|
{ |
93 |
|
|
- DBG_ASSERT( false, "!! Grammarchecker failed to provide end of sentence !!" ); |
94 |
|
|
- aRes.nBehindEndOfSentencePosition = nSuggestedEnd; |
95 |
|
|
+ // no grammar checker -> no error |
96 |
|
|
+ // but we need to provide the data below in order to continue with the next sentence |
97 |
|
|
+ aRes.aDocumentIdentifier = aCurDocId; |
98 |
|
|
+ aRes.xFlatParagraph = xFlatPara; |
99 |
|
|
+ aRes.aText = aCurTxt; |
100 |
|
|
+ aRes.aLocale = aCurLocale; |
101 |
|
|
+ aRes.nStartOfSentencePosition = nStartPos; |
102 |
|
|
+ aRes.nBehindEndOfSentencePosition = nSuggestedEnd; |
103 |
|
|
} |
104 |
|
|
+ aRes.nStartOfNextSentencePosition = lcl_SkipWhiteSpaces( aCurTxt, aRes.nBehindEndOfSentencePosition ); |
105 |
|
|
+ aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( aCurTxt, aRes.nStartOfNextSentencePosition ); |
106 |
|
|
|
107 |
|
|
- aRes.xFlatParagraph = xFlatPara; |
108 |
|
|
- aRes.nStartOfSentencePosition = nStartPos; |
109 |
|
|
+ //guard has to be cleared as ProcessResult calls out of this class |
110 |
|
|
+ aGuard.clear(); |
111 |
|
|
+ ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic ); |
112 |
|
|
+ // ---- THREAD SAFE END ---- |
113 |
|
|
} |
114 |
|
|
else |
115 |
|
|
{ |
116 |
|
|
- // no grammar checker -> no error |
117 |
|
|
- // but we need to provide the data below in order to continue with the next sentence |
118 |
|
|
- aRes.aDocumentIdentifier = aCurDocId; |
119 |
|
|
- aRes.xFlatParagraph = xFlatPara; |
120 |
|
|
- aRes.aText = aCurTxt; |
121 |
|
|
- aRes.aLocale = aCurLocale; |
122 |
|
|
- aRes.nStartOfSentencePosition = nStartPos; |
123 |
|
|
- aRes.nBehindEndOfSentencePosition = nSuggestedEnd; |
124 |
|
|
+ // the paragraph changed meanwhile... (and maybe is still edited) |
125 |
|
|
+ // thus we simply continue to ask for the next to be checked. |
126 |
|
|
+ uno::Reference< text::XFlatParagraph > xFlatParaNext( xFPIterator->getNextPara() ); |
127 |
|
|
+ AddEntry( xFPIterator, xFlatParaNext, aCurDocId, 0, aFPEntryItem.m_bAutomatic ); |
128 |
|
|
} |
129 |
|
|
- aRes.nStartOfNextSentencePosition = lcl_SkipWhiteSpaces( aCurTxt, aRes.nBehindEndOfSentencePosition ); |
130 |
|
|
- aRes.nBehindEndOfSentencePosition = lcl_BacktraceWhiteSpaces( aCurTxt, aRes.nStartOfNextSentencePosition ); |
131 |
|
|
- |
132 |
|
|
- //guard has to be cleared as ProcessResult calls out of this class |
133 |
|
|
- aGuard.clear(); |
134 |
|
|
- ProcessResult( aRes, xFPIterator, aFPEntryItem.m_bAutomatic ); |
135 |
|
|
- // ---- THREAD SAFE END ---- |
136 |
|
|
} |
137 |
|
|
- else |
138 |
|
|
+ catch (css::uno::Exception & e) |
139 |
|
|
{ |
140 |
|
|
- // the paragraph changed meanwhile... (and maybe is still edited) |
141 |
|
|
- // thus we simply continue to ask for the next to be checked. |
142 |
|
|
- uno::Reference< text::XFlatParagraph > xFlatParaNext( xFPIterator->getNextPara() ); |
143 |
|
|
- AddEntry( xFPIterator, xFlatParaNext, aCurDocId, 0, aFPEntryItem.m_bAutomatic ); |
144 |
|
|
+ SAL_WARN( |
145 |
|
|
+ "linguistic", |
146 |
|
|
+ "GrammarCheckingIterator::DequeueAndCheck ignoring UNO" |
147 |
|
|
+ " exception " << e.Message); |
148 |
|
|
} |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
-- |
152 |
|
|
1.9.3 |
153 |
|
|
|