Handle missing resources.
Needed for unit tests related to various bug fixes.
Bug 19930761.
Change-Id: I776ccccb032e3d1b181b02c6bb768500790870f7
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index e00532a..f4300c4 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -91,10 +91,15 @@
*/
public static AssetFileAddress loadFallbackResource(final Context context,
final int fallbackResId) {
- final AssetFileDescriptor afd = context.getResources().openRawResourceFd(fallbackResId);
+ AssetFileDescriptor afd = null;
+ try {
+ afd = context.getResources().openRawResourceFd(fallbackResId);
+ } catch (RuntimeException e) {
+ Log.e(TAG, "Resource not found: " + fallbackResId, e);
+ return null;
+ }
if (afd == null) {
- Log.e(TAG, "Found the resource but cannot read it. Is it compressed? resId="
- + fallbackResId);
+ Log.e(TAG, "Resource cannot be opened: " + fallbackResId);
return null;
}
try {
@@ -103,8 +108,7 @@
} finally {
try {
afd.close();
- } catch (IOException e) {
- // Ignored
+ } catch (IOException ignored) {
}
}
}