-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[path_provider] Fix Unchecked/Unsafe Operation Warning #5267
Conversation
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. |
I don't have experience with Java generics, so @blasten would be a better reviewer in this case. |
@@ -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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
import static io.flutter.plugin.common.BinaryMessenger.*; | ||
import static io.flutter.plugin.common.MethodChannel.*; |
There was a problem hiding this comment.
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.
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. |
Unfortunately it's not quite that simple; just making warnings fatal when we have no warnings will break plugin clients. See flutter/flutter#91868 |
Fixes warning mentioned in Issue #93389.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).