-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[Widget Inspector] Handle null exceptions calling renderObject
#163642
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
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). 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. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
kenzieschmoll
left a comment
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 w/ one comment
| /// If the call to get the render object throws, the result will be null. | ||
| RenderObject? _renderObjectOrNull(Element element) { | ||
| try { | ||
| return element.renderObject; |
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.
you can check if this is mounted first that guaranteed to be non null if mounted is true
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.
Thank you for the review!
It looks like this is the mounted getter:
| bool get mounted => _widget != null; |
However, it's checking if _widget is non-null, not _renderObject. From what I can tell, _widget is set as part of the createElement step, whereas the _renderObject is set as part of the mount step:
flutter/packages/flutter/lib/src/widgets/framework.dart
Lines 3465 to 3471 in 8876bcc
| /// * The framework creates an element by calling [Widget.createElement] on the | |
| /// widget that will be used as the element's initial configuration. | |
| /// * The framework calls [mount] to add the newly created element to the tree | |
| /// at a given slot in a given parent. The [mount] method is responsible for | |
| /// inflating any child widgets and calling [attachRenderObject] as | |
| /// necessary to attach any associated render objects to the render tree. | |
| /// * At this point, the element is considered "active" and might appear on |
So I think we would still hit the null-pointer exception when the element has been created but not mounted:
| assert(_renderObject != null, '$runtimeType unmounted'); |
I might be missing something here though!
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.
looking at the code, I think creating element will synchronouslly mount the element and thus create renderobject. If you find a case it is not, this should be a bug that we need to fix.
| final Element newChild = newWidget.createElement(); |
See line 4534 created the element and mount directly in line 4539
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.
Got it, thanks! Switched to checking if the element is mounted.
Still trying to figure out how best to add tests for this
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.
Added a test case (and confirmed it fails without this change)
chunhtai
left a comment
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
flutter/flutter@6b93cf9...b16430b 2025-03-10 [email protected] [macOS] Enable Impeller by default on macOS. (flutter/flutter#164572) 2025-03-10 [email protected] Roll Packages from 4c5a7ed to 464cea5 (5 revisions) (flutter/flutter#164904) 2025-03-10 [email protected] Roll Skia from f17d37ee0ac6 to 4ac86f17f2d4 (1 revision) (flutter/flutter#164893) 2025-03-10 [email protected] Roll Skia from 0f53870c7449 to f17d37ee0ac6 (1 revision) (flutter/flutter#164887) 2025-03-09 [email protected] Roll Fuchsia Linux SDK from 6tAcm4hdtXPE55GJP... to U-zlyIZrZRbr9I6gv... (flutter/flutter#164868) 2025-03-09 [email protected] Roll Skia from 345dc2d05dcd to 0f53870c7449 (1 revision) (flutter/flutter#164865) 2025-03-08 [email protected] Roll Skia from 916caa2f0102 to 345dc2d05dcd (1 revision) (flutter/flutter#164843) 2025-03-08 [email protected] Roll Fuchsia Linux SDK from ixl5bKWCqsRiYGvps... to 6tAcm4hdtXPE55GJP... (flutter/flutter#164838) 2025-03-08 [email protected] Roll Skia from b29851b2ada6 to 916caa2f0102 (1 revision) (flutter/flutter#164835) 2025-03-08 [email protected] [Impeller] add capability check for extended range formats. (flutter/flutter#164817) 2025-03-08 [email protected] Added calendar delegate to support custom calendar systems (flutter/flutter#161874) 2025-03-08 [email protected] RoundSuperellipse algorithm v3: Ultrawideband heuristic formula (flutter/flutter#164755) 2025-03-08 [email protected] Merge CHANGELOG for 3.29.1 stable release (flutter/flutter#164743) 2025-03-08 [email protected] Add and link to `Infra-Triage.md`. (flutter/flutter#164673) 2025-03-07 [email protected] Roll Skia from cbc7e99d6c2f to b29851b2ada6 (10 revisions) (flutter/flutter#164812) 2025-03-07 [email protected] [Impeller] dont redundantly set stencil reference on vulkan backend. (flutter/flutter#164763) 2025-03-07 [email protected] content-aware-hash experiment update (flutter/flutter#164803) 2025-03-07 [email protected] [Widget Inspector] Handle null exceptions calling `renderObject` (flutter/flutter#163642) 2025-03-07 [email protected] Use Python 3.12 to run the yapf formatter if no lower version is available (flutter/flutter#164807) 2025-03-07 [email protected] Roll gn to 7a8aa3a08a13521336853a28c46537ec04338a2d (flutter/flutter#164806) 2025-03-07 [email protected] [Impeller] Store the TextureGLES cached framebuffer object as a reactor handle (flutter/flutter#164761) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/flutter@6b93cf9...b16430b 2025-03-10 [email protected] [macOS] Enable Impeller by default on macOS. (flutter/flutter#164572) 2025-03-10 [email protected] Roll Packages from 4c5a7ed to 464cea5 (5 revisions) (flutter/flutter#164904) 2025-03-10 [email protected] Roll Skia from f17d37ee0ac6 to 4ac86f17f2d4 (1 revision) (flutter/flutter#164893) 2025-03-10 [email protected] Roll Skia from 0f53870c7449 to f17d37ee0ac6 (1 revision) (flutter/flutter#164887) 2025-03-09 [email protected] Roll Fuchsia Linux SDK from 6tAcm4hdtXPE55GJP... to U-zlyIZrZRbr9I6gv... (flutter/flutter#164868) 2025-03-09 [email protected] Roll Skia from 345dc2d05dcd to 0f53870c7449 (1 revision) (flutter/flutter#164865) 2025-03-08 [email protected] Roll Skia from 916caa2f0102 to 345dc2d05dcd (1 revision) (flutter/flutter#164843) 2025-03-08 [email protected] Roll Fuchsia Linux SDK from ixl5bKWCqsRiYGvps... to 6tAcm4hdtXPE55GJP... (flutter/flutter#164838) 2025-03-08 [email protected] Roll Skia from b29851b2ada6 to 916caa2f0102 (1 revision) (flutter/flutter#164835) 2025-03-08 [email protected] [Impeller] add capability check for extended range formats. (flutter/flutter#164817) 2025-03-08 [email protected] Added calendar delegate to support custom calendar systems (flutter/flutter#161874) 2025-03-08 [email protected] RoundSuperellipse algorithm v3: Ultrawideband heuristic formula (flutter/flutter#164755) 2025-03-08 [email protected] Merge CHANGELOG for 3.29.1 stable release (flutter/flutter#164743) 2025-03-08 [email protected] Add and link to `Infra-Triage.md`. (flutter/flutter#164673) 2025-03-07 [email protected] Roll Skia from cbc7e99d6c2f to b29851b2ada6 (10 revisions) (flutter/flutter#164812) 2025-03-07 [email protected] [Impeller] dont redundantly set stencil reference on vulkan backend. (flutter/flutter#164763) 2025-03-07 [email protected] content-aware-hash experiment update (flutter/flutter#164803) 2025-03-07 [email protected] [Widget Inspector] Handle null exceptions calling `renderObject` (flutter/flutter#163642) 2025-03-07 [email protected] Use Python 3.12 to run the yapf formatter if no lower version is available (flutter/flutter#164807) 2025-03-07 [email protected] Roll gn to 7a8aa3a08a13521336853a28c46537ec04338a2d (flutter/flutter#164806) 2025-03-07 [email protected] [Impeller] Store the TextureGLES cached framebuffer object as a reactor handle (flutter/flutter#164761) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/flutter@6b93cf9...b16430b 2025-03-10 [email protected] [macOS] Enable Impeller by default on macOS. (flutter/flutter#164572) 2025-03-10 [email protected] Roll Packages from 4c5a7ed to 464cea5 (5 revisions) (flutter/flutter#164904) 2025-03-10 [email protected] Roll Skia from f17d37ee0ac6 to 4ac86f17f2d4 (1 revision) (flutter/flutter#164893) 2025-03-10 [email protected] Roll Skia from 0f53870c7449 to f17d37ee0ac6 (1 revision) (flutter/flutter#164887) 2025-03-09 [email protected] Roll Fuchsia Linux SDK from 6tAcm4hdtXPE55GJP... to U-zlyIZrZRbr9I6gv... (flutter/flutter#164868) 2025-03-09 [email protected] Roll Skia from 345dc2d05dcd to 0f53870c7449 (1 revision) (flutter/flutter#164865) 2025-03-08 [email protected] Roll Skia from 916caa2f0102 to 345dc2d05dcd (1 revision) (flutter/flutter#164843) 2025-03-08 [email protected] Roll Fuchsia Linux SDK from ixl5bKWCqsRiYGvps... to 6tAcm4hdtXPE55GJP... (flutter/flutter#164838) 2025-03-08 [email protected] Roll Skia from b29851b2ada6 to 916caa2f0102 (1 revision) (flutter/flutter#164835) 2025-03-08 [email protected] [Impeller] add capability check for extended range formats. (flutter/flutter#164817) 2025-03-08 [email protected] Added calendar delegate to support custom calendar systems (flutter/flutter#161874) 2025-03-08 [email protected] RoundSuperellipse algorithm v3: Ultrawideband heuristic formula (flutter/flutter#164755) 2025-03-08 [email protected] Merge CHANGELOG for 3.29.1 stable release (flutter/flutter#164743) 2025-03-08 [email protected] Add and link to `Infra-Triage.md`. (flutter/flutter#164673) 2025-03-07 [email protected] Roll Skia from cbc7e99d6c2f to b29851b2ada6 (10 revisions) (flutter/flutter#164812) 2025-03-07 [email protected] [Impeller] dont redundantly set stencil reference on vulkan backend. (flutter/flutter#164763) 2025-03-07 [email protected] content-aware-hash experiment update (flutter/flutter#164803) 2025-03-07 [email protected] [Widget Inspector] Handle null exceptions calling `renderObject` (flutter/flutter#163642) 2025-03-07 [email protected] Use Python 3.12 to run the yapf formatter if no lower version is available (flutter/flutter#164807) 2025-03-07 [email protected] Roll gn to 7a8aa3a08a13521336853a28c46537ec04338a2d (flutter/flutter#164806) 2025-03-07 [email protected] [Impeller] Store the TextureGLES cached framebuffer object as a reactor handle (flutter/flutter#164761) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…tter#163642) Fixes flutter/devtools#8905 Based on the stacktrace in flutter/devtools#8905: * This call to `renderObject` can throw a null-exception: https://github.com/flutter/flutter/blob/39b4951f8f0bb7a32532ee2f67e83a783b065b58/packages/flutter/lib/src/widgets/framework.dart#L3745 * That exception is thrown here: https://github.com/flutter/flutter/blob/39b4951f8f0bb7a32532ee2f67e83a783b065b58/packages/flutter/lib/src/widgets/framework.dart#L6534 I've been unable to figure out a way to get into a state that reproduces this. Instead, this PR simply handles the exception and returns `null` (because we already gracefully handle the case where the `renderObject` is `null`.
Fixes flutter/devtools#8905
Based on the stacktrace in flutter/devtools#8905:
renderObjectcan throw a null-exception:flutter/packages/flutter/lib/src/widgets/framework.dart
Line 3745 in 39b4951
flutter/packages/flutter/lib/src/widgets/framework.dart
Line 6534 in 39b4951
I've been unable to figure out a way to get into a state that reproduces this. Instead, this PR simply handles the exception and returns
null(because we already gracefully handle the case where therenderObjectisnull.