Closed yccheok closed 3 years ago
This is a serious issue and should be fixed. I'm having the same issues..
I'm having the same issue. Is there a way to pre-check the array size?
Hi @yccheok, in order to return the correct type,getItemViewType
depends a lot on Section properties (isVisible, hasHeader, hasFooter, getState, getSectionItemsTotal..). If those properties are changed during the execution of getItemViewType
it might cause IndexOutOfBoundsException.
Since by design the adapter has a map of mutable Sections, and Section is implemented by the user, it's out of the adapter's control to make sure that they are not changed while they are iterated on. So if you want to prevent this issue, you would have to make sure that the Sections properties are not changed when getItemViewType
is running.
I'm afraid I don't think we cannot make the library prevent this issue without a big change on the design. The Section class would have to provide a Collection to hold its items instead of letting the user to use whatever collection they want to. The Section class would have to also provide methods to add/remove/update its items, in other words, the library would have control on every item that it's added to the adapter.
I'm marking as help wanted for now, but if no further investigation is done, I will mark it as "wontfix".
Hem...
Thanks for the tip. Your hypothesis does make sense. However, when I re-exam my code, which perform mutate operation on Sections
, all of them are performed within UI thread. Hence, if the Section mutate operations are truly performed within UI thread, it seems like modifying Section
's properties, and calling getItemViewType
shouldn't happen simultaneously.
Unless, the value passed from Android system int position
is wrong...
I'm having the same issues..
Describe the bug Randomly and rarely, we encounter strange
java.lang.IndexOutOfBoundsException
duringsectionedRecyclerViewAdapter.getSectionItemViewType
Expected behavior No random crash.
Screenshots If applicable, add screenshots to help explain your problem.
SectionedRecyclerViewAdapter library:
Additional context Here's the online crash report.
MVCE