aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/DictionaryFactory.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2011-07-19 18:16:34 +0900
committerJean Chalard <jchalard@google.com>2011-07-19 18:19:23 +0900
commit44861474fbea784f12fe86bc56d30d5d9be4ad81 (patch)
treef61cd516e95f2590e9610c4ac2d0aea2ccc30359 /java/src/com/android/inputmethod/latin/DictionaryFactory.java
parent494ab16396077f12a7c07414318f256e7ae11633 (diff)
downloadlatinime-44861474fbea784f12fe86bc56d30d5d9be4ad81.tar.gz
latinime-44861474fbea784f12fe86bc56d30d5d9be4ad81.tar.xz
latinime-44861474fbea784f12fe86bc56d30d5d9be4ad81.zip
Add a number of NULL pointer guards.
None of these are expected to actually be null, but those are included for peace of mind and foolproofing against future code changes. Bug: 4580040 Change-Id: Ib112b3e5db5f177aaf61767164b7e78d711f90a0
Diffstat (limited to 'java/src/com/android/inputmethod/latin/DictionaryFactory.java')
-rw-r--r--java/src/com/android/inputmethod/latin/DictionaryFactory.java20
1 files changed, 15 insertions, 5 deletions
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<Dictionary> dictList = new LinkedList<Dictionary>();
- for (final AssetFileAddress f : BinaryDictionaryGetter.getDictionaryFiles(locale,
- context, fallbackResId)) {
- dictList.add(new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null));
+ final List<AssetFileAddress> 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);
+ }
}
/**