am b95f4540: Merge "Fix a possible deadlock."

* commit 'b95f4540180fe707c80dc987eaa965342623407b':
  Fix a possible deadlock.
This commit is contained in:
Jean Chalard 2011-09-26 02:32:35 -07:00 committed by Android Git Automerger
commit 722636d9ba

View file

@ -334,10 +334,19 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final String text = textInfo.getText(); final String text = textInfo.getText();
if (shouldFilterOut(text)) { if (shouldFilterOut(text)) {
final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull(); DictAndProximity dictInfo = null;
if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS; try {
return dictInfo.mDictionary.isValidWord(text) ? IN_DICT_EMPTY_SUGGESTIONS dictInfo = mDictionaryPool.takeOrGetNull();
: NOT_IN_DICT_EMPTY_SUGGESTIONS; if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS;
return dictInfo.mDictionary.isValidWord(text) ? IN_DICT_EMPTY_SUGGESTIONS
: NOT_IN_DICT_EMPTY_SUGGESTIONS;
} finally {
if (null != dictInfo) {
if (!mDictionaryPool.offer(dictInfo)) {
Log.e(TAG, "Can't re-insert a dictionary into its pool");
}
}
}
} }
final SuggestionsGatherer suggestionsGatherer = final SuggestionsGatherer suggestionsGatherer =
@ -361,19 +370,25 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final int capitalizeType = getCapitalizationType(text); final int capitalizeType = getCapitalizationType(text);
boolean isInDict = true; boolean isInDict = true;
final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull(); DictAndProximity dictInfo = null;
if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS; try {
dictInfo.mDictionary.getWords(composer, suggestionsGatherer, dictInfo = mDictionaryPool.takeOrGetNull();
dictInfo.mProximityInfo); if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS;
isInDict = dictInfo.mDictionary.isValidWord(text); dictInfo.mDictionary.getWords(composer, suggestionsGatherer,
if (!isInDict && CAPITALIZE_NONE != capitalizeType) { dictInfo.mProximityInfo);
// We want to test the word again if it's all caps or first caps only. isInDict = dictInfo.mDictionary.isValidWord(text);
// If it's fully down, we already tested it, if it's mixed case, we don't if (!isInDict && CAPITALIZE_NONE != capitalizeType) {
// want to test a lowercase version of it. // We want to test the word again if it's all caps or first caps only.
isInDict = dictInfo.mDictionary.isValidWord(text.toLowerCase(mLocale)); // If it's fully down, we already tested it, if it's mixed case, we don't
} // want to test a lowercase version of it.
if (!mDictionaryPool.offer(dictInfo)) { isInDict = dictInfo.mDictionary.isValidWord(text.toLowerCase(mLocale));
Log.e(TAG, "Can't re-insert a dictionary into its pool"); }
} finally {
if (null != dictInfo) {
if (!mDictionaryPool.offer(dictInfo)) {
Log.e(TAG, "Can't re-insert a dictionary into its pool");
}
}
} }
final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text, final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text,