Bug 817386 - Log and ignore IndexOutOfBoundsException in Editable; r=cpeterson a=bbajaj
authorJim Chen <nchen@mozilla.com>
Tue, 15 Jan 2013 12:31:32 -0500
changeset 127138 006d27ddd615f2a40c0b94b0357c8390291ecbb9
parent 127137 8233d14cdc575bc56dafcc8234d9f02e7f501a8b
child 127139 1f852f68169c22708c27d6ce9c6c37b3bbb6fbdf
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpeterson, bbajaj
bugs817386
milestone20.0a2
Bug 817386 - Log and ignore IndexOutOfBoundsException in Editable; r=cpeterson a=bbajaj
mobile/android/base/GeckoEditable.java
--- a/mobile/android/base/GeckoEditable.java
+++ b/mobile/android/base/GeckoEditable.java
@@ -18,16 +18,17 @@ import android.text.SpannableStringBuild
 import android.text.Selection;
 import android.text.TextPaint;
 import android.text.TextUtils;
 import android.text.style.CharacterStyle;
 import android.util.Log;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.Semaphore;
 
 // interface for the UI thread
 interface GeckoEditableClient {
     void sendEvent(GeckoEvent event);
@@ -725,17 +726,40 @@ final class GeckoEditable
             // Method alters the Editable; route calls to our implementation
             target = this;
         } else {
             // Method queries the Editable; must sync with Gecko first
             // then call on the inner Editable itself
             mActionQueue.syncWithGecko();
             target = mText;
         }
-        Object ret = method.invoke(target, args);
+        Object ret;
+        try {
+            ret = method.invoke(target, args);
+        } catch (InvocationTargetException e) {
+            // Bug 817386
+            // Most likely Gecko has changed the text while GeckoInputConnection is
+            // trying to access the text. If we pass through the exception here, Fennec
+            // will crash due to a lack of exception handler. Log the exception and
+            // return an empty value instead.
+            if (!(e.getCause() instanceof IndexOutOfBoundsException)) {
+                // Only handle IndexOutOfBoundsException for now,
+                // as other exceptions might signal other bugs
+                throw e;
+            }
+            Log.w(LOGTAG, "Exception in GeckoEditable." + method.getName(), e.getCause());
+            Class<?> retClass = method.getReturnType();
+            if (retClass != Void.TYPE && retClass.isPrimitive()) {
+                ret = retClass.newInstance();
+            } else if (retClass == String.class) {
+                ret = "";
+            } else {
+                ret = null;
+            }
+        }
         if (DEBUG) {
             StringBuilder log = new StringBuilder(method.getName());
             log.append("(");
             for (Object arg : args) {
                 debugAppend(log, arg).append(", ");
             }
             if (args.length > 0) {
                 log.setLength(log.length() - 2);