[BUG] Crash in PreviewImagePagerAdapter (Play Console)
Actual behaviour
Crash with some appearances in Play Console. It's a IndexOutOfBoundsException:
Exception java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at jdk.internal.util.Preconditions.outOfBounds (Preconditions.java:64)
at jdk.internal.util.Preconditions.outOfBoundsCheckIndex (Preconditions.java:70)
at jdk.internal.util.Preconditions.checkIndex (Preconditions.java:266)
at java.util.Objects.checkIndex (Objects.java:359)
at java.util.ArrayList.get (ArrayList.java:434)
at com.owncloud.android.ui.preview.PreviewImagePagerAdapter.getFileAt (PreviewImagePagerAdapter.kt:63)
at com.owncloud.android.ui.preview.PreviewImageActivity.onPageSelected (PreviewImageActivity.kt:304)
at com.owncloud.android.ui.preview.PreviewImageActivity.initViewPager$lambda$6$lambda$5 (PreviewImageActivity.kt:225)
at com.owncloud.android.ui.preview.PreviewImageActivity.$r8$lambda$wt1a57YPNw2a74PZoE3yXT9Mdxg (Unknown Source)
at com.owncloud.android.ui.preview.PreviewImageActivity$$ExternalSyntheticLambda2.run (D8$$SyntheticClass)
at android.os.Handler.handleCallback (Handler.java:959)
at android.os.Handler.dispatchMessage (Handler.java:100)
at android.os.Looper.loopOnce (Looper.java:257)
at android.os.Looper.loop (Looper.java:342)
at android.app.ActivityThread.main (ActivityThread.java:9634)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:619)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:929)
Expected behaviour
No crash
Steps to reproduce
Undefined
override fun onPageSelected(position: Int) {
...
val currentFile = previewImagePagerAdapter.getFileAt(position)
...
}
The crash is triggered when PreviewImagePagerAdapter is created before SortFilesUseCase has finished. In this case, the image list is empty, so when the method getFileAt(position) is called, the app crashes due to an index out-of-bounds error. To fix this, I've added a check before accessing the list: if it's empty (previewImagePagerAdapter.count == 0) the app will be return the user to the previous view, otherwise it will work as expected.
/run-tests
@KelvinProsper34 what did you try?
@jesmrec I tried to initiate a workflow so I could look into this issue. I couldn't, because I'm not yet a collaborator. I hope to be a collaborator on this project soon.
@KelvinProsper34 we have no trigger or workflow listening with such name. Anyway, current issue is already fixed and closed.
If you want to collaborate, please check our CONTRIBUTING file with the master guidelines, and for sure, ask us here or in talk.owncloud.com (you can chat with us directly).
As first work, i'd recommend you any issue with the "Contributions are welcome" tag.
Fixed starting from v4.6.0