Skip to content

Audit callback list iteration in the framework #131678

@dnfield

Description

@dnfield

See #131415 (comment)

There are at least a few places in widgets binding where we do or do not make copies of the observers before firing them, for example - but any of those callbacks could add or remove observers. We should go through and find the places where this is getting handled incorrectly.

@pq do you think it would be helpful/possible to have an annotation for these kinds of lists? For example, if you create a list of callbacks, having some annotation on it that warns you not to iterate it unless it was a copy. E.g.

// BAD

for (final callback in _callbacks) {
  callback();
}

// GOOD

for (final callback in List.of(_callbacks)) {
  callback();
}

// OK, but weird.
for (final callback in _callbacks) {
  // Do something else but do not callback().
}

So we'd have something like final List<MyCallbackableThing> _callbacks; annotated with something like @onlyIterateCopies or something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions