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
main
Jean Chalard 2011-07-19 18:16:34 +09:00
parent 494ab16396
commit 44861474fb
3 changed files with 23 additions and 7 deletions

View File

@ -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);
}
}
}

View File

@ -32,7 +32,11 @@ public class DictionaryCollection extends Dictionary {
}
public DictionaryCollection(Dictionary... dictionaries) {
mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries);
if (null == dictionaries) {
mDictionaries = new CopyOnWriteArrayList<Dictionary>();
} else {
mDictionaries = new CopyOnWriteArrayList<Dictionary>(dictionaries);
}
}
public DictionaryCollection(Collection<Dictionary> dictionaries) {

View File

@ -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);
}
}
/**