Bug 817386 - Log and ignore IndexOutOfBoundsException in Editable; r=cpeterson
authorJim Chen <nchen@mozilla.com>
Wed, 09 Jan 2013 11:57:31 -0500
changeset 118249 efddd115fd76af1e2e0c1273814db0177b7e37b1
parent 118248 dff10a89c17cd2701870682af6a8a189028ca3e6
child 118250 50752f340d6cdf7b34552cfd2add4729ac393b9a
push id20949
push usernchen@mozilla.com
push dateWed, 09 Jan 2013 16:58:37 +0000
treeherdermozilla-inbound@50752f340d6c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpeterson
bugs817386
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 817386 - Log and ignore IndexOutOfBoundsException in Editable; r=cpeterson
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);