ChartsOrg / ChartsOrg/Charts

notifyDataChanged() will crash for dataset without entries

Open
#1,945 7 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

More specifically
Setting CandleChartData with a dataset containing 0 entries and then calling data?.notifyDataChanged() will cause a crash.

I think this happens because it will try to reference entries using subscript index, so probably tries to get entries[0] (because count = 0) and that obviously won't work because that entries doesn't exist.

A workaround is to check if your dataset contains any entries and set it data to nil otherwise.

However, I think Charts could improve here by either using safe subscript referencing (so you can check entries[0] safely without crashing) or just checking if there are actual entries before trying to subscript access them.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue by assigning a CandleChartData dataset with zero entries and calling data?.notifyDataChanged(). Trace the empty-dataset path to the entries subscript access; done means notifyDataChanged() no longer crashes when the dataset has no entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.