Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventController.removeAll generates a concurrencymodification exception #443

Open
bsutton opened this issue Jan 2, 2025 · 0 comments
Open

Comments

@bsutton
Copy link
Contributor

bsutton commented Jan 2, 2025

The removeAll method causes a concurrency modification exception when you try to remove all events from the controller.

  _weekController
        ..removeAll(_weekController.allEvents)
        ..addAll(eventData);
  /// Removes all the [events] from this controller.
  void removeAll(List<CalendarEventData<T>> events) {
    for (final event in events) {
      _calendarData.removeEvent(event);
    }
    notifyListeners();
  }

causes a

ConcurrentModificationError (Concurrent modification during iteration: Instance of 'UnmodifiableListView<CalendarEventData<JobEventEx>>'.)

So the issue is that I'm trying to remove all events from the controller so I can reload it.
Obviously passing in the same list of events as we are going to iterate over is always going to be an issue.

There does feel like there is an api design flaw here, because the events we need to remove are always going to be held in the controller.

A couple of solutions:
Add a 'clear' method to the api to clear the list of events from the controller - this will reduce the chance that someone will
use the api the way I did.

Have the code always iterate over a copy of the events - could be expensive give that each event holds user data.

Add a comment in the api doc to warn the user might be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant