question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

position in `fun isStickyHead(position: Int)` larger than models size.

See original GitHub issue

I want a summary model to be the sticky header so I added the following check.

override fun isStickyHeader(position: Int): Boolean {
    return adapter.getModelAtPosition(position).let { it is SummaryModel }
}

I noticed that after the state of this view changed, under some circumstances the view would crash. Through debugging I found that the position that passed into this function was larger than the count of the models. I have to do a check like this:

override fun isStickyHeader(position: Int): Boolean {
    return position < adapter.copyOfModels.size  && adapter.getModelAtPosition(position).let { it is SummaryModel }
}

However, I feel pretty weird about it. I wonder if it is a bug in this library?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
samuelchoucommented, Nov 8, 2021

I encountered the similar problem, except when isStickyHeader is called, the position value it passed is negative.

I’m using Epoxy 4.6.4.

Fatal Exception: java.lang.IndexOutOfBoundsException: Invalid item position -88(-88). Item count:94 com.airbnb.epoxy.EpoxyRecyclerView{c9f6fc8 VFED..... ......ID 0,816-1080,2631 #7f080199 app:id/itemContainer}, adapter:com.airbnb.epoxy.EpoxyControllerAdapter@e3de88d, layout:com.airbnb.epoxy.stickyheader.StickyHeaderLinearLayoutManager@7452a42, context:dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper@7100797
       at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6326)
       at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6300)
       at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6296)
       at com.airbnb.epoxy.stickyheader.StickyHeaderLinearLayoutManager.createStickyHeader(StickyHeaderLinearLayoutManager.kt:283)
       at com.airbnb.epoxy.stickyheader.StickyHeaderLinearLayoutManager.updateStickyHeader(StickyHeaderLinearLayoutManager.kt:253)
       at com.airbnb.epoxy.stickyheader.StickyHeaderLinearLayoutManager.onLayoutChildren(StickyHeaderLinearLayoutManager.kt:111)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4309)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4012)
       // ...

So I decided to use more safe-condition in isStickyHeader:

override fun isStickyHeader(position: Int): Boolean {
    return if (adapter.itemCount <= position || position < 0) {
        val exception = IndexOutOfBoundsException("Size: ${adapter.itemCount}, called: $position")
        Log.w(
            TAG, "isStickyHeader: called at illegal position. IGNORED and treat as viewed as not-header.",
            exception
        )
        FirebaseCrashlytics.getInstance().recordException(exception)
        false
    } else {
        adapter.getModelAtPosition(position) is MyStickyHeaderBindingModel_
    }
}

I’ll just leave it here to warn future users. (And to wait for fix, of course.)

2reactions
WessimBetcliccommented, Jun 3, 2022

Hello ! Any news on this particular bug ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Int) larger than models size in Epoxy android? - Stack Overflow
Position in fun isStickyHead(position: Int) larger than models size ... override fun buildModels(data: DataModel) { RoleHeader(interactor, ...
Read more >
Modify a bit at a given position - GeeksforGeeks
We first create a mask that has set bit only at given position using bit wise shift. mask = 1 << position Then...
Read more >
C++ Programming Review 3 Answers
For example, write code to dynamically allocate an array of 5 integers, initialize the array to { 10, 20, 30, 40, 50 },...
Read more >
C# Decimal vs Double and Other Tips About Number Types
Learn about precision vs accuracy and when to use int, double, ... In other words, the range of double is several times larger...
Read more >
Numeric Data Types - Snowflake Documentation
Snowflake also supports the FLOAT data type, which allows a wider range of values, although with less precision. DECIMAL , NUMERIC¶. Synonymous with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found