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

Fix bug handling cyclic diagnostics. #31960

Merged
merged 1 commit into from
May 2, 2019
Merged

Conversation

jacob314
Copy link
Contributor

@jacob314 jacob314 commented May 2, 2019

Description

Cases where there was a cycle involving diagnostics referenced in a property and their properties could cause some InspectorService methods to stack overflow.

Related Issues

This pull request fixes
#31959

Tests

I added the following tests:

I added a test that reproduces the cyclic diagnostic without having to depend on the specific Diagnosticables that currently have cyclic dependencies and then make the test pass by fixing the bug.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@@ -2486,7 +2486,7 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
json['exception'] = exception.toString();
json['propertyType'] = propertyType.toString();
json['defaultLevel'] = describeEnum(_defaultLevel);
if (T is Diagnosticable || T is DiagnosticsNode)
if (value is Diagnosticable || value is DiagnosticsNode)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the type of the value is more useful in this case as you can't expand a null value anyway. My test was failing until I fixed this somewhat minor bug.

@@ -1487,17 +1487,32 @@ mixin WidgetInspectorService {
}

if (config.includeProperties) {
List<DiagnosticsNode> properties = node.getProperties();
if (properties.isEmpty && value is Diagnosticable) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was the problem case. The fix could have been just to remove these 4 lines which I added in error. They are not safe as cycles between property values and their properties could lead to a stack overflow.

Inspecting this code I also noticed the previous code could sometimes override the json['properties'] field if a DiagnosticsProperty subclass returned properties as well has having a value that was Diagnosticable so I cleaned that case up.

@@ -1515,7 +1583,7 @@ class TestWidgetInspectorService extends Object with WidgetInspectorService {
_CreationLocation location = knownLocations[id];
expect(location.file, equals(file));
// ClockText widget.
expect(location.line, equals(50));
expect(location.line, equals(51));
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 had to update these line #s due to the added import at the top of the file.

@jacob314 jacob314 merged commit e17f9e8 into flutter:master May 2, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants