Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

collinjackson
Copy link
Contributor

@collinjackson collinjackson commented Jan 4, 2022

  • Introduce verify, a more future-proof name. It throws AssertionError if const Object() used as the instance's token.
  • Soft-deprecate verifyToken with a comment. It will actually deprecated in a future release, to avoid breaking tests with this minor change.
  • Update documentation for PlatformInterface to show new usage of verify and other cosmetic fixes.
  • Add a test for the new assertion.

Fixes flutter/flutter#96178.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter]. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the [CLA].
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style].
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

/// This is implemented as a static method so that it cannot be overridden
/// with `noSuchMethod`.
static void verifyToken(PlatformInterface instance, Object token) {
assert(token != const Object());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per discussion in the issue, we can't add this without making a breaking version change. What we can do though is soft-deprecate this (i.e., put a comment that it shouldn't be used any more, but not an annotation since that would break our own builds) and make a new method that has this assertion then calls verifyToken.

(We can then update all the 1P plugins to call the new method, then make it a real deprecation and move the implementation to a shared private method so we're not calling the deprecated version.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented your suggested changes, PTAL

@collinjackson collinjackson changed the title [plugin_platform_interface] Update documentation for PlatformInterface. [plugin_platform_interface] Add a new method verify that prevents use of const Object() as token. Jan 5, 2022
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nits, but otherwise LGTM. Thanks for following up on this!

# Please consider carefully before bumping the major version of this package, ideally it should only
# be done when absolutely necessary and after the ecosystem has already migrated to 1.X.Y version
# that is forward compatible with 2.0.0 (ideally the ecosystem have migrated to depend on:
# `plugin_platform_interface: >=1.X.Y <3.0.0`).
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g Jan 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the versions in this comment need to be updated as well (1->2, 2->3, 3->4)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks.

PlatformInterface.verify(instance, _token);
// A real implementation would set a static instance field here.
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make a version of this that still uses verifyToken so we're still exercising the codepath that >100 plugins are likely currently using, to make sure we don't break it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@collinjackson
Copy link
Contributor Author

@stuartmorgan: Can you please land and publish this for me when you get a chance? I think it's done. Thanks for the feedback!

@stuartmorgan-g stuartmorgan-g merged commit 72634e0 into flutter:master Jan 6, 2022
@stuartmorgan-g
Copy link
Contributor

I didn't realize you didn't have commit permissions still; if you need a sponsor to be added back just let me know :)

and publish

We live in the future now! PRs with version changes are automatically published once post-submit tests pass.

@collinjackson
Copy link
Contributor Author

I didn't realize you didn't have commit permissions still; if you need a sponsor to be added back just let me know :)

I will take you up on that! But I have to land "several" PRs to be eligible, so please review #4643 next.

and publish

We live in the future now! PRs with version changes are automatically published once post-submit tests pass.

🎉

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 6, 2022
@stuartmorgan-g
Copy link
Contributor

But I have to land "several" PRs to be eligible

🤣

Screen Shot 2022-01-06 at 10 08 46 AM

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

Successfully merging this pull request may close these issues.

[plugin_platform_interface] Prevent use of const Object() as token
2 participants