Skip to content

[BUG] Crash in PreviewImagePagerAdapter (Play Console) #4596

Closed

Description

@joragua

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

Image

Activity

  1. self-assigned this
    on Jun 12, 2025
  2. added this to the 4.6 - Current milestone on Jun 13, 2025
  3. joragua commented on Jun 13, 2025

    @joragua
    MemberAuthor
    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.

  4. KelvinProsper34 commented on Jun 13, 2025

    @KelvinProsper34

    /run-tests

  5. jesmrec commented on Jun 16, 2025

    @jesmrec
    Member

    @KelvinProsper34 what did you try?

  6. KelvinProsper34 commented on Jun 16, 2025

    @KelvinProsper34

    @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.

  7. jesmrec commented on Jun 17, 2025

    @jesmrec
    Member

    @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.

  8. joragua commented on Aug 8, 2025

    @joragua
    MemberAuthor

    Fixed starting from v4.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions