Skip to content

NavigatorObserver._navigator needs reworking due to an upcoming dart language change #109237

Closed

Description

@stereotype441

The dart language team will soon be changing the behavior of the language so that an invocation of a private class members won't get dispatched to a noSuchMethod method in another library; instead an exception will be thrown. This is a necessary prerequisite to allowing promotion of private fields (dart-lang/language#2020). It also closes an important privacy loophole in the language, by ensuring that the user can see all the possible behaviors of a private member invocation without having to look outside of the library.

This has an important consequence for tests using mockito, in the scenario where a private class member is referenced from outside of its containing class, and the containing class instance is replaced with a mock, but the reference isn't replaced with a mock. Previously, in this scenario, the invocation would be dispatched to Mock.noSuchMethod; with the upcoming language change it will throw an exception.

This situation arises with NavigatorObserver._navigator, which is referenced from the NavigatorState class; if a test mocks NavigatorObserver but not NavigatorState, it will likely fail. It could be argued that such tests should be rewritten to use a less brittle mocking strategy, but there are enough examples of this pattern in Google's internal code base that it seems likely that it exists in code belonging to other customers too.

After discussion with @goderbauer, we believe the best approach to avoid a widespread breakage is to rework NavigatorObserver in a way that preserves its user-facing API, but so that it doesn't contain a private member that's referred to by other classes.

Activity

  1. self-assigned this
    on Aug 9, 2022
  2. added
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: routesNavigator, Router, and related APIs.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Aug 10, 2022
  3. github-actions commented on Aug 24, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  4. locked as resolved and limited conversation to collaborators on Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: proposalA detailed proposal for a change to Flutterf: routesNavigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions