Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paging: IndexOutOfBounds #420

Closed
alashow opened this issue Apr 13, 2018 · 3 comments
Closed

Paging: IndexOutOfBounds #420

alashow opened this issue Apr 13, 2018 · 3 comments

Comments

@alashow
Copy link

alashow commented Apr 13, 2018

When using epoxy with paging, before calling controller.setList() I have to check if the list is not empty and call it only if not empty.
Otherwise app crashes with the following exception:

java.lang.IndexOutOfBoundsException: Index: 0
        at java.util.Collections$EmptyList.get(Collections.java:4500)
        at android.arch.paging.PagedStorage.getFirstLoadedItem(PagedStorage.java:238)
        at android.arch.paging.ContiguousPagedList.schedulePrepend(ContiguousPagedList.java:189)
        at android.arch.paging.ContiguousPagedList.loadAroundInternal(ContiguousPagedList.java:170)
        at android.arch.paging.PagedList.loadAround(PagedList.java:380)
        at com.airbnb.epoxy.paging.PagingEpoxyController.onModelBound(PagingEpoxyController.java:127)
        at com.airbnb.epoxy.EpoxyControllerAdapter.onModelBound(EpoxyControllerAdapter.java:81)
        at com.airbnb.epoxy.BaseEpoxyAdapter.onBindViewHolder(BaseEpoxyAdapter.java:108)
        at com.airbnb.epoxy.EpoxyControllerAdapter.onBindViewHolder(EpoxyControllerAdapter.java:10)
        at com.airbnb.epoxy.BaseEpoxyAdapter.onBindViewHolder(BaseEpoxyAdapter.java:14)
// crash with IOB
viewModel.liveList.behold(this) { controller.setList(it) }

// works
viewModel.liveList.behold(this) {
    if (it?.isNotEmpty() == true) {
       controller.setList(it)
    }
}

// viewModel.liveList
val liveList by lazy(mode = LazyThreadSafetyMode.NONE) {
        LivePagedListBuilder<Int, Model>(
                dao.dataSourceFactory(),
                PagedList.Config.Builder().run {
                    setPageSize(21)
                    setEnablePlaceholders(false)
                    build()
                }
        ).run {
            build()
        }
}
@elihart
Copy link
Contributor

elihart commented Apr 16, 2018

Thanks for reporting! I'll try to have a fix for this soon

@elihart
Copy link
Contributor

elihart commented Apr 16, 2018

Fixed with #421

Also, since you use this would you mind commenting on the other change bundled with that? I think reading the config off the PagedList will be nice to reduce duplication of needing to specify them again on the EpoxyController.

@alashow
Copy link
Author

alashow commented Apr 17, 2018

Actually, I wasn't specifying any configurations on my controller. I assumed it was already reading from PagedList. So that's a good change!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants