-
-
Notifications
You must be signed in to change notification settings - Fork 54
Description
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.