Skip to content

Crash on horizontal drag gesture when linesPathData is empty #114

@digitalapps21

Description

@digitalapps21

App crashes with an IndexOutOfBoundsException when attempting to interact with a LineChart that has no data. This occurs during a horizontal drag gesture, due to accessing an empty linesPathData list without bounds checking.

Trace:

Exception java.lang.IndexOutOfBoundsException: Empty list doesn't contain element at index 0. at kotlin.collections.EmptyList.get (Collections.kt:37) at ir.ehsannarmani.compose_charts.LineChartKt$LineChart$12$2$1$1.invokeSuspend$lambda$4 (LineChart.kt:289) at androidx.compose.foundation.gestures.DragGestureDetectorKt$detectHorizontalDragGestures$5.invokeSuspend (DragGestureDetector.kt:638)

Relevant Code (LineChart.kt:289):

val pathData = linesPathData[dataIndex]

Suggested Fix:

Add a guard clause or use a safe access method:

if (linesPathData.isNotEmpty() && dataIndex in linesPathData.indices) { val pathData = linesPathData[dataIndex] ... }

OR

val pathData = linesPathData.getOrNull(dataIndex) if (pathData != null) { ... }

Steps to Reproduce:

Render a LineChart with an empty data list.

Attempt to drag horizontally on the chart.

Observe crash.

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