代码之家  ›  专栏  ›  技术社区  ›  Oleg Gryb

Android在TextView中崩溃,indexoutboundsexception没有自定义代码的痕迹

  •  0
  • Oleg Gryb  · 技术社区  · 5 年前

    我的Android应用程序在运行Android9的设备上的TextView中的某个地方崩溃。它发生在SpannableStringBuilder.checkRange中的参数验证期间。我的应用程序中有很多TextView对象,但还不清楚是哪一个导致了这个问题以及原因,因为堆栈跟踪中没有提供自定义代码。

    这是一个非常罕见的崩溃,我无法复制它,所以使用调试器不是一个选项。播放存储报告此崩溃的以下设备、内部版本和版本:

    Samsung Galaxy S10+ (beyond2q), Android 9 
    

    我已经反编译了SpannableStringBuilder.checkRange,在最后一个条件下,它的第1326行指向“throw”语句如下所示:

    start < 0 || end < 0
    

    SpannableStringBuilder#检查范围代码:

    private void checkRange(final String operation, int start, int end) {
        if (end < start) {
            throw new IndexOutOfBoundsException(operation + " " +
                    region(start, end) + " has end before start");
        }
    
        int len = length();
    
        if (start > len || end > len) {
            throw new IndexOutOfBoundsException(operation + " " +
                    region(start, end) + " ends beyond length " + len);
        }
    
        if (start < 0 || end < 0) {
            throw new IndexOutOfBoundsException(operation + " " +
                    region(start, end) + " starts before 0");
        }
    }
    

    1. 有什么方法可以在自定义代码中识别出崩溃发生的位置吗?
    2. 有没有什么方法可以在应用程序级别修复它,或者这是一个需要系统修复的Android平台问题?

    堆栈跟踪:

        java.lang.IndexOutOfBoundsException: 
          at android.text.SpannableStringBuilder.checkRange (SpannableStringBuilder.java:1326)
          at android.text.SpannableStringBuilder.setSpan (SpannableStringBuilder.java:682)
          at android.text.SpannableStringBuilder.setSpan (SpannableStringBuilder.java:674)
          at android.text.method.ArrowKeyMovementMethod.onTouchEvent (ArrowKeyMovementMethod.java:255)
          at android.widget.TextView.onTouchEvent (TextView.java:11355)
          at android.view.View.dispatchTouchEvent (View.java:13484)
          at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
          at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
          at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
          at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
          at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
          at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
          at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
          at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
          at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
          at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
          at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3222)
          at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2845)
          at com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:697)
          at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1879)
          at android.app.Activity.dispatchTouchEvent (Activity.java:3487)
          at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:69)
          at com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:655)
          at android.view.View.dispatchPointerEvent (View.java:13732)
          at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:6119)
          at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:5897)
          at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5346)
          at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5399)
          at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5365)
          at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:5524)
          at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5373)
          at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:5581)
          at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:5346)
          at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:5399)
          at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:5365)
          at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:5373)
          at android.view.ViewRootImpl$InputStage.deliver 
    (ViewRootImpl.java:5346)
          at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:8408)
          at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:8341)
          at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:8294)
          at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:8523)
          at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:198)
          at android.os.MessageQueue.nativePollOnce (MessageQueue.java)
          at android.os.MessageQueue.next (MessageQueue.java:326)
          at android.os.Looper.loop (Looper.java:181)
          at android.app.ActivityThread.main (ActivityThread.java:7037)
          at java.lang.reflect.Method.invoke (Method.java)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494)
          at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)
    
    0 回复  |  直到 5 年前