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

[path_provider] Fix Unchecked/Unsafe Operation Warning #5267

Merged
merged 12 commits into from
Apr 26, 2022

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented Apr 14, 2022

Fixes warning mentioned in Issue #93389.

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.

@camsim99 camsim99 marked this pull request as ready for review April 14, 2022 18:47
@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 (don't just cc him here, he won't see it! He's on Discord!).

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.

@stuartmorgan
Copy link
Contributor

I don't have experience with Java generics, so @blasten would be a better reviewer in this case.

@stuartmorgan stuartmorgan requested review from blasten and removed request for stuartmorgan April 14, 2022 20:22
@@ -157,15 +157,17 @@ private void setup(BinaryMessenger messenger, Context context) {
// TODO(gaaclarke): Remove reflection guard when https://github.com/flutter/engine/pull/29147
// becomes available on the stable branch.
try {
Class methodChannelClass = Class.forName("io.flutter.plugin.common.MethodChannel");
Class taskQueueClass = Class.forName("io.flutter.plugin.common.BinaryMessenger$TaskQueue");
Class<?> methodChannelClass = Class.forName("io.flutter.plugin.common.MethodChannel");
Copy link

Choose a reason for hiding this comment

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

@gaaclarke are these APIs available on the stable branch, right? If yes, let's remove TODO and workaround.

Copy link
Contributor

Choose a reason for hiding this comment

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

Be sure to set the right minimum Flutter version for the package if you do this; the legacy tests on CI are Dart analysis only so won't catch it.

Copy link
Contributor Author

@camsim99 camsim99 Apr 15, 2022

Choose a reason for hiding this comment

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

Based on the release notes, the fix should have made it to Flutter 2.8.0 which is the current minimum Flutter version. The guard is still there, though, to catch exceptions.

Copy link

Choose a reason for hiding this comment

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

it looks like we can remove the dynamic lookups, and import io.flutter.plugin.common.MethodChannel statically, etc... This only requires changing flutter: ">=2.8.0" to flutter: ">=2.8.1" in pubspec.yaml

@camsim99 camsim99 requested a review from blasten April 15, 2022 22:07
Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 7 to 8
import static io.flutter.plugin.common.BinaryMessenger.*;
import static io.flutter.plugin.common.MethodChannel.*;
Copy link

Choose a reason for hiding this comment

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

nit: here and below, avoid wildcard imports: https://google.github.io/styleguide/javaguide.html#s3.3.1-wildcard-imports

I tend to think it's ok to use wildcards in test code, in particular for very repetitive imports like org.junit.Assert or Mockito imports, other than that wildcards makes it harder to reason about when reading some code.

@Hixie
Copy link
Contributor

Hixie commented Apr 25, 2022

test-exempt: code refactor with no semantic change

for bonus points, you could make the warnings fatal, that would be a good way to test this. Only works once there's no warnings though.

@stuartmorgan
Copy link
Contributor

stuartmorgan commented Apr 25, 2022

for bonus points, you could make the warnings fatal, that would be a good way to test this. Only works once there's no warnings though.

Unfortunately it's not quite that simple; just making warnings fatal when we have no warnings will break plugin clients. See flutter/flutter#91868

@camsim99 camsim99 added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Apr 26, 2022
@fluttergithubbot fluttergithubbot merged commit 3e43f59 into flutter:main Apr 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs tests p: path_provider platform-android waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants