diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 7ce92920d..bce787db2 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -91,7 +91,9 @@ class BinaryDictionaryGetter { Log.e(TAG, "Unable to read source data for locale " + locale.toString() + ": falling back to internal dictionary"); } - return Arrays.asList(loadFallbackResource(context, fallbackResId)); + final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId); + if (null == fallbackAsset) return null; + return Arrays.asList(fallbackAsset); } } } diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java index 5e7de3e6b..e987d9f0c 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -32,7 +32,11 @@ public class DictionaryCollection extends Dictionary { } public DictionaryCollection(Dictionary... dictionaries) { - mDictionaries = new CopyOnWriteArrayList(dictionaries); + if (null == dictionaries) { + mDictionaries = new CopyOnWriteArrayList(); + } else { + mDictionaries = new CopyOnWriteArrayList(dictionaries); + } } public DictionaryCollection(Collection dictionaries) { diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index bba331868..a35b0f5b0 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -52,13 +52,23 @@ public class DictionaryFactory { } final List dictList = new LinkedList(); - for (final AssetFileAddress f : BinaryDictionaryGetter.getDictionaryFiles(locale, - context, fallbackResId)) { - dictList.add(new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null)); + final List assetFileList = + BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId); + if (null != assetFileList) { + for (final AssetFileAddress f : assetFileList) { + dictList.add( + new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null)); + } } - if (null == dictList) return null; - return new DictionaryCollection(dictList); + // null == dictList is not supposed to be possible, but better safe than sorry and it's + // safer for future extension. In this case, rather than returning null, it should be safer + // to return an empty DictionaryCollection. + if (null == dictList) { + return new DictionaryCollection(); + } else { + return new DictionaryCollection(dictList); + } } /**