square / cycler

Apache License 2.0
791 stars 27 forks source link

ArrayIndexOutOfBoundsException thrown when subtype has an undefined RowSpec #30

Closed luis-cortes closed 3 years ago

luis-cortes commented 4 years ago

This can be reproduced easily by creating another subclass of BaseItem and adding it to the sample list in SimplePage without changing the config.

BaseItem.kt

  data class NewType(
    val id: Int,
    override val amount: Float
  ): BaseItem()

SimplePage.kt

 private fun sampleList() =
    listOf(
        NewType(6, 7f),
        Discount(5, -5f, isStarred = true)
    )

Stack Trace

java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1
    at java.util.ArrayList.get(ArrayList.java:439)
    at com.squareup.cycler.Recycler$Adapter.getItemViewType(Recycler.kt:443)

Can we get another exception thrown here make the issue more obvious?

Fantastic work on this library! I refuse to work with RecyclerView any other way 🙂

helios175 commented 4 years ago

Thanks! I will address this soon.

helios175 commented 4 years ago

Addressed in #31 (still to be published in a new version)

luis-cortes commented 3 years ago

Addressed in 0.1.5.