IndexOutOfBoundsException in Favorite view having duplicate entries
⚠️ Before posting ⚠️
- [X] This is a bug, not a question or an enhancement.
- [X] I've searched for similar issues and didn't find a duplicate.
- [X] I've written a clear and descriptive title for this issue, not just "Bug" or "Crash".
- [X] I agree to follow Nextcloud's Code of Conduct.
Steps to reproduce
- Open Favorite view in app
- Scroll down
### Cause of error
```java
Exception in thread "main" java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionOCFileListItemViewHolder{845b55b position=16 id=-1, oldPos=-1, pLpos:-1 no parent} com.owncloud.android.ui.EmptyRecyclerView{4c12421 VFED..... .......D 0,0-1080,2134 #7f0a0286 app:id/list_root}, adapter:com.owncloud.android.ui.adapter.OCFileListAdapter@8466ba, layout:androidx.recyclerview.widget.LinearLayoutManager@d88996b, context:com.owncloud.android.ui.activity.FileDisplayActivity@f567254
at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:6156)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6339)
at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:288)
at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:345)
at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:361)
at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:368)
at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:399)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
App information
- ID:
com.nextcloud.client - Version:
30210290 - Build flavor:
generic
Device information
- Brand:
Xiaomi - Device:
lavender - Model:
Redmi Note 7 - Id:
RQ3A.211001.001 - Product:
lineage_lavender
Firmware
- SDK:
30 - Release:
11 - Incremental:
eng.root.20220718.044033
### Expected behaviour
Should not crash
### Actual behaviour
Crashes. See above.
Strange thing is that all my Favorite folders or files are been listed multiple (there) times.
### Android version
11
### Device brand and model
Xiaomi Redmi Note 7
### Stock or custom OS?
Custom (explain in "additional information")
### Nextcloud android app version
30210290
### Nextcloud server version
23
### Using a reverse proxy?
Yes
### Android logs
_No response_
### Server error logs
_No response_
### Additional information
Lineage OS
is this bug still open?i want to work on it.
Yes it is still open. Go for it.
Yes it is still open. Go for it. thanks!!!!!
@nextcloud-bot can you please assign it to me?
Yes it is still open. Go for it.
if possible ,can you assign it to me?
@ayushbhanu please stop spamming comments. If you want to work on something, start working on it and open a draft PR. We don't assign tickets to random people.
Any news @ayushbhanu ?
Any news @ayushbhanu ?
Hey @myxor I am able to replicate the issue ,it is sometime there other time not , trying to figure it out furthur.
Hey @myxor and @AlvaroBrey I have resolved this issue . This issue occurred because RecyclerView Data modified in different thread,this is actually a bug in recycler view which is still not resolved. I have worked out on creating a wrapper class for List and Grid Layout and overriding onLayoutChildren to catch out this exception and app will run smoothly although this error not always occur , it is sometimes there other time not . Also I have added code to clear the view before setting a new adapter.I have also raised a PR request ,please have a review .
PR link - https://github.com/nextcloud/android/pull/11112
Fixed in #12357 and #11519