Remove a broken dictionary file when fail to read a dictionary file.
Bug: 10434720
Change-Id: Ibdf05a39113538546b8fcf9d59af7dddf7ca27fc
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
index 29f1146..ceb8fa8 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictDecoderUtils.java
@@ -561,8 +561,7 @@
*/
@UsedForTesting
/* package */ static FusionDictionary readDictionaryBinary(final Ver3DictDecoder dictDecoder,
- final FusionDictionary dict) throws FileNotFoundException, IOException,
- UnsupportedFormatException {
+ final FusionDictionary dict) throws IOException, UnsupportedFormatException {
// Read header
final FileHeader fileHeader = dictDecoder.readHeader();
diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
index 1fff9b4..1a5023e 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java
@@ -25,6 +25,8 @@
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
import com.android.inputmethod.latin.utils.JniUtils;
+import android.util.Log;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -38,6 +40,7 @@
*/
@UsedForTesting
public class Ver3DictDecoder implements DictDecoder {
+ private static final String TAG = Ver3DictDecoder.class.getSimpleName();
static {
JniUtils.loadNativeLibrary();
@@ -308,7 +311,21 @@
if (mDictBuffer == null) {
openDictBuffer();
}
- return BinaryDictDecoderUtils.readDictionaryBinary(this, dict);
+ try {
+ return BinaryDictDecoderUtils.readDictionaryBinary(this, dict);
+ } catch (IOException e) {
+ Log.e(TAG, "The dictionary " + mDictionaryBinaryFile.getName() + " is broken.", e);
+ if (!mDictionaryBinaryFile.delete()) {
+ Log.e(TAG, "Failed to delete the broken dictionary.");
+ }
+ throw e;
+ } catch (UnsupportedFormatException e) {
+ Log.e(TAG, "The dictionary " + mDictionaryBinaryFile.getName() + " is broken.", e);
+ if (!mDictionaryBinaryFile.delete()) {
+ Log.e(TAG, "Failed to delete the broken dictionary.");
+ }
+ throw e;
+ }
}
@Override