Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_tools] Fix tool crash for map cast #107648

Merged
merged 5 commits into from
Aug 9, 2022

Conversation

dnys1
Copy link
Contributor

@dnys1 dnys1 commented Jul 14, 2022

Fixes a flutter_tools crash when generating localizations due to a cast of jsonDecode output to Map<String, Object> in a null-safe library.

List which issues are fixed by this PR. You must list at least one issue.

#107647

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

N/A

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 Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • 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.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@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.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 14, 2022
Copy link
Member

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

Can you add a test for this change?

@dnys1
Copy link
Contributor Author

dnys1 commented Jul 15, 2022

@christopherfujino I can, but I'm not sure what I would test. It's clearly a miss from the null-safety migration of this library. I guess because the flutter tool is still built in unsound mode, it's not caught. But casting the result of jsonDecode to anything but Map<String, Object?>/Map<String, dynamic> should fail as this does is my understanding.

Please let me know how you'd go about testing this change and I'd be happy to implement it.

@christopherfujino
Copy link
Member

@christopherfujino I can, but I'm not sure what I would test. It's clearly a miss from the null-safety migration of this library. I guess because the flutter tool is still built in unsound mode, it's not caught. But casting the result of jsonDecode to anything but Map<String, Object?>/Map<String, dynamic> should fail as this does is my understanding.

Please let me know how you'd go about testing this change and I'd be happy to implement it.

Hmm, that's a good point, this would be difficult to test. I would then suggest following the bot's guidance on requesting a test exemption.

@Hixie
Copy link
Contributor

Hixie commented Jul 16, 2022

Wouldn't the test be basically what the code that found the crash in the first place was doing?

(@christopherfujino if you think it should be test-exempt I defer to your expertise)

@dnys1
Copy link
Contributor Author

dnys1 commented Jul 18, 2022

Thanks for the quick reply, @Hixie.

I think that makes sense. Since the issue is in the localization generation code, it is only triggered when running flutter pub get in a directory with localizations. I couldn't find a test which best fit this, but I felt it best belonged in the pub_get_test.dart file.

Since this issue will only be triggered in null-safety mode, I've added a separate commit to migrate pub_get_test.dart before adding this test.

@christopherfujino Let me know if that all makes sense and if I approached this correctly, or if I need to open a separate PR for the migration.

Cheers!

@dnys1
Copy link
Contributor Author

dnys1 commented Jul 28, 2022

Hey @christopherfujino, just pinging to get your thoughts. Would love to merge this and/or update as needed. Thanks!

@christopherfujino
Copy link
Member

Hey @christopherfujino, just pinging to get your thoughts. Would love to merge this and/or update as needed. Thanks!

whoops, sorry I missed this, LGTM.

Copy link
Member

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

LGTM

@dnys1
Copy link
Contributor Author

dnys1 commented Aug 8, 2022

Hi @Jasguerrero - checking in to see if you think we could merge this? Let me know if you have any concerns.

testUsingContext('pub get triggers localizations generation when generate: true', () async {
final File pubspecFile = fileSystem.currentDirectory.childFile('pubspec.yaml')
..createSync();
pubspecFile.writeAsStringSync('''
Copy link
Contributor

Choose a reason for hiding this comment

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

nit on the identation for this and next writeAsStringSync

pubspecFile.writeAsStringSync(
  '''
  flutter:
    generate: true
  '''
);

Copy link
Contributor Author

@dnys1 dnys1 Aug 9, 2022

Choose a reason for hiding this comment

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

Fixed, thanks! Did you mean for all three or just the first two? Sorry - couldn't follow the heuristic in the latter case if I misunderstood.

Copy link
Contributor

@Jasguerrero Jasguerrero left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants