From: Reimar Döffinger Date: Thu, 21 May 2020 19:44:04 +0000 (+0200) Subject: Make more robust by catching some exceptions. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=1ef7686713e8930fcb03e45c28805390cb8e6b5a Make more robust by catching some exceptions. --- diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index 05893c0..840f2d8 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -853,7 +853,10 @@ public class DictionaryActivity extends AppCompatActivity { @Override public void run() { searchTextView.setThreshold(0); - searchTextView.showDropDown(); + try { + searchTextView.showDropDown(); + // ignore any errors, in particular BadTokenException happens a lot + } catch (Exception e) {} } }); } diff --git a/src/com/hughes/android/dictionary/engine/Dictionary.java b/src/com/hughes/android/dictionary/engine/Dictionary.java index 5b209b0..0398431 100644 --- a/src/com/hughes/android/dictionary/engine/Dictionary.java +++ b/src/com/hughes/android/dictionary/engine/Dictionary.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.io.RandomAccessFile; +import java.nio.BufferUnderflowException; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.util.ArrayList; @@ -212,6 +213,10 @@ public class Dictionary { // Most likely due to a Buffer.limit beyond size of file, // do not crash just because of a truncated dictionary file return getErrorDictionaryInfo(file); + } catch (BufferUnderflowException e) { + // Most likely due to a read beyond the buffer limit set, + // do not crash just because of a truncated or corrupt dictionary file + return getErrorDictionaryInfo(file); } finally { if (raf != null) { try {