From 30cd0cd2a034f7323f71654df3aaad3abd8ca3a3 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Fri, 28 Mar 2014 12:17:44 +0900 Subject: [PATCH] Fix: NPE after onDestroy(). Bug: 13671513 Change-Id: I06aa14870ff5422ad514356ee406600b247858c5 --- .../inputmethod/latin/ExpandableBinaryDictionary.java | 9 +++++++++ .../inputmethod/latin/utils/LanguageModelParam.java | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 7847738e0..3c1015926 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -269,6 +269,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } private void runGCAfterAllPrioritizedTasksIfRequiredLocked(final boolean mindsBlockByGC) { + if (mBinaryDictionary == null) { + return; + } // needsToRunGC() have to be called with lock. if (mBinaryDictionary.needsToRunGC(mindsBlockByGC)) { if (setProcessingLargeTaskIfNot()) { @@ -357,6 +360,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { public void run() { final boolean locked = setProcessingLargeTaskIfNot(); try { + if (mBinaryDictionary == null) { + return; + } mBinaryDictionary.addMultipleDictionaryEntries( languageModelParams.toArray( new LanguageModelParam[languageModelParams.size()])); @@ -496,6 +502,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } private void flushDictionaryLocked() { + if (mBinaryDictionary == null) { + return; + } if (mBinaryDictionary.needsToRunGC(false /* mindsBlockByGC */)) { mBinaryDictionary.flushWithGC(); } else { diff --git a/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java b/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java index acd16a9e4..5ce977d5e 100644 --- a/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java +++ b/java/src/com/android/inputmethod/latin/utils/LanguageModelParam.java @@ -110,6 +110,9 @@ public final class LanguageModelParam { final LanguageModelParam languageModelParam = detectWhetherVaildWordOrNotAndGetLanguageModelParam( prevWord, tempWord, timestamp, dictionaryFacilitator); + if (languageModelParam == null) { + continue; + } languageModelParams.add(languageModelParam); prevWord = languageModelParam.mTargetWord; } @@ -120,6 +123,9 @@ public final class LanguageModelParam { final String prevWord, final String targetWord, final int timestamp, final DictionaryFacilitatorForSuggest dictionaryFacilitator) { final Locale locale = dictionaryFacilitator.getLocale(); + if (locale == null) { + return null; + } if (!dictionaryFacilitator.isValidWord(targetWord, true /* ignoreCase */)) { // OOV word. return createAndGetLanguageModelParamOfWord(prevWord, targetWord, timestamp,