Skip to content

🐛 LineChart crash in showPopup (IndexOutOfBoundsException) even when caller guards empty data #158

@lopspower

Description

@lopspower

🐛 LineChart crash in showPopup (IndexOutOfBoundsException)

Hi 👋
Thanks for the library 🙏

I’m getting a crash in LineChart inside showPopup (LineChart.kt:270).
Important detail: this is NOT simply because my data list is empty, because I already guard it right before rendering the chart:

if (data.isEmpty()) return

LineChart(
        modifier = Modifier.fillMaxSize()
            .padding(start = 14.dp, end = 14.dp, top = 10.dp, bottom = 6.dp),
        data = data,
        animationMode = AnimationMode.Together(delayBuilder = { it * 100L }),
        popupProperties = PopupProperties(
            textStyle = TextStyle(
                fontSize = 10.sp,
                fontWeight = FontWeight.SemiBold,
                color = MaterialTheme.colorScheme.primary,
                fontFamily = FontFamily(Font(Res.font.myfont))
            ),
            contentBuilder = { popup ->
                CurrencyHelper.priceFormat(popup.value, price.profileCurrency, isFrench)
            },
            containerColor = Color.White
        ),
        indicatorProperties = HorizontalIndicatorProperties(
            textStyle = TextStyle(
                fontSize = 10.sp,
                fontFamily = FontFamily(Font(Res.font.myfont)),
                color = Color.White
            ),
            contentBuilder = {
                CurrencyHelper.priceFormat(it, price.profileCurrency, isFrench)
            },
        ),
        labelHelperProperties = LabelHelperProperties(
            textStyle = TextStyle(
                fontSize = 11.sp,
                fontWeight = FontWeight.SemiBold,
                fontFamily = FontFamily(Font(Res.font.myfont)),
                color = Color.White
            )
        ),
        labelHelperPadding = 12.dp,
        labelProperties = LabelProperties(
            enabled = true,
            padding = 4.dp,
            labels = dates,
            textStyle = TextStyle(
                fontSize = 10.sp,
                fontFamily = FontFamily(Font(Res.font.myfont)),
                color = Color.White
            ),
            rotation = LabelProperties.Rotation(mode = Mode.Force, degree = 0f, padding = 4.dp)
        ),
        minValue = min,
        maxValue = max,
    )

Crash

Fatal Exception: java.lang.IndexOutOfBoundsException: index: 0, size: 0
at androidx.compose.runtime.external.kotlinx.collections.immutable.internal.ListImplementation.checkElementIndex$runtime(ListImplementation.kt:15)
at androidx.compose.runtime.external.kotlinx.collections.immutable.implementations.immutableList.SmallPersistentVector.get(SmallPersistentVector.kt:146)
at androidx.compose.runtime.snapshots.SnapshotStateList.get(SnapshotStateList.android.kt:79)
at ir.ehsannarmani.compose_charts.LineChartKt.LineChart_tpvImbo$showPopup(LineChart.kt:270)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions