Skip to content

IndexOutOfBoundsException in SlideAdapter.getSlide called from canGoBackward #162

@joeykrim

Description

@joeykrim

I'm seeing a similar IndexOutOfBoundsException issue as (#103), but with the onBackPressed and canGoBackward methods, which in theory should not happen as the position shouldn't exceed the number of cards added/available (in my scenario 3 cards).
I'm not able to re-produce the issue locally, but I am seeing this occur on Samsung and Huawei devices with Android version 4.4.2 and 6.0.1.
I'm using the latest version of this library - v1.6.

As a patch, I've added your fix (6b09a88) from the canGoForward method if (position >= getCount()) to the onBackPressed method to also return false for any position values higher than the index rather than pass them along to the getSlide method which throws the IndexOutOfBoundsException. The additional condition in onBackPressed now looks this: if (position <= 0 || position >= getCount()) return false;

Stacktrace is for 3 welcome screen slides being added:

Fatal Exception: java.lang.IndexOutOfBoundsException: Invalid index 3, size is 3
       at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
       at java.util.ArrayList.get(ArrayList.java:308)
       at com.heinrichreimersoftware.materialintro.app.IntroActivity.com.heinrichreimersoftware.materialintro.slide.SlideAdapter.getSlide(SourceFile:8096)
       at com.heinrichreimersoftware.materialintro.app.IntroActivity.canGoBackward(SourceFile:455)
       at com.heinrichreimersoftware.materialintro.app.IntroActivity.previousSlide(SourceFile:410)
       at com.heinrichreimersoftware.materialintro.app.IntroActivity.onBackPressed(SourceFile:224)
       at android.app.Activity.onKeyUp(Activity.java:2273)
       at android.view.KeyEvent.dispatch(KeyEvent.java:3232)
       at android.app.Activity.dispatchKeyEvent(Activity.java:2507)
       at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(SourceFile:543)
       at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(SourceFile:53)
       at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(SourceFile:315)
       at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2178)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4409)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4376)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3941)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3995)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3964)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4075)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3972)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4132)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3941)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3995)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3964)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3972)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3941)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3995)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3964)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4108)
       at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4268)
       at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2201)
       at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1848)
       at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1839)
       at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2178)
       at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:138)
       at android.os.Looper.loop(Looper.java:131)
       at android.app.ActivityThread.main(ActivityThread.java:5511)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
       at dalvik.system.NativeStart.main(NativeStart.java)

Metadata

Metadata

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions