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 "
|
Log.e(TAG, "Unable to read source data for locale "
|
||||||
+ locale.toString() + ": falling back to internal dictionary");
|
+ 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,7 +32,11 @@ public class DictionaryCollection extends Dictionary {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DictionaryCollection(Dictionary... dictionaries) {
|
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) {
|
public DictionaryCollection(Collection<Dictionary> dictionaries) {
|
||||||
|
|
|
@ -52,13 +52,23 @@ public class DictionaryFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Dictionary> dictList = new LinkedList<Dictionary>();
|
final List<Dictionary> dictList = new LinkedList<Dictionary>();
|
||||||
for (final AssetFileAddress f : BinaryDictionaryGetter.getDictionaryFiles(locale,
|
final List<AssetFileAddress> assetFileList =
|
||||||
context, fallbackResId)) {
|
BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId);
|
||||||
dictList.add(new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, null));
|
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
|
||||||
return new DictionaryCollection(dictList);
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue