Hitting an error filtering items from a `MutableSt...
# compose
w
Hitting an error filtering items from a
MutableState<List<Device>?>
inside a
LazyColumn
.
Device
is a custom data class. I am populating the
LazyColumn
with a
forEach
off my list.
deviceList.value?.forEach {
I early return if my string search filter is not found. Then the error throws. Sometimes on seemingly random string searches. Meat and potatoes of my filter
Copy code
if (search.value.isNotEmpty()) {
    if (!device.DeviceName.contains(
            search.value,
            ignoreCase = true
        ) && !device.Serial.contains(search.value, ignoreCase = true)
    ) {
        return@forEach
    }
}
item {
    DeviceButton(navController, device, accountId)
}
I can't wrap my head around this error:
Copy code
FATAL EXCEPTION: main
Process: com.wwdev.example.mobile, PID: 3504
java.lang.IndexOutOfBoundsException: Index 1, size 1
at androidx.compose.foundation.lazy.layout.MutableIntervalList.checkIndexBounds(IntervalList.kt:183)
The main device list is not changing. All filtering is done inside the same forEach block. Seemingly the list that is calling the forEach is changing, but it isn't. I have deviceList defined as:
Copy code
val deviceList = remember {mutableStateOf(deviceVM.devices.value)}
It works, until it doesn't. Can get a few filters in then it will crash. View model list stays the same throughout.
z
Which version of compose are you on? Might be this and if your stacktrace contains mentions of Lookahead~ they mentioned it being fixed in the next alpha release (I cant find the issue where they mention it, but its out there somewhere).
w
@Zoltan Demant That stack trace seems to match mine. I see my build.gradle didn't specify a version on compose.ui. I assume that means current release.
Confirmed same behavior on 1.6.0-alpha08. Will keep an eye on that ticket for a resolve. Thanks
🙏🏽 1
🙏 1
v
I have a similar stack trace in one of our e2e tests when trying to upgrade to compose 1.6.0-alpha08
Untitled
Commented on the issue and upvoted
👍🏽 1