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: Ib112b3e5db5f177aaf61767164b7e78d711f90a0main
parent
494ab16396
commit
44861474fb
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,8 +32,12 @@ public class DictionaryCollection extends Dictionary {
|
|||
}
|
||||
|
||||
public DictionaryCollection(Dictionary... dictionaries) {
|
||||
if (null == dictionaries) {
|
||||
mDictionaries = new CopyOnWriteArrayList<Dictionary>();
|
||||
} else {
|
||||
mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries);
|
||||
}
|
||||
}
|
||||
|
||||
public DictionaryCollection(Collection<Dictionary> dictionaries) {
|
||||
mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries);
|
||||
|
|
|
@ -52,14 +52,24 @@ 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;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a dictionary from a raw resource file
|
||||
|
|
Loading…
Reference in New Issue