Skip to content

Conversation

@elliette
Copy link
Member

Fixes flutter/devtools#8905

Based on the stacktrace in flutter/devtools#8905:

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.

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

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Feb 19, 2025
Copy link
Member

@kenzieschmoll kenzieschmoll left a 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;
Copy link
Contributor

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

Copy link
Member Author

@elliette elliette Mar 6, 2025

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:

/// * 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!

Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

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)

Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@elliette elliette added this pull request to the merge queue Mar 7, 2025
Merged via the queue into flutter:master with commit b7bea22 Mar 7, 2025
72 of 74 checks passed
@elliette elliette deleted the issue-8905 branch March 7, 2025 21:49
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 10, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Mar 10, 2025
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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
androidseb pushed a commit to androidseb/packages that referenced this pull request Jun 8, 2025
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
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
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
romanejaquez pushed a commit to romanejaquez/flutter that referenced this pull request Aug 14, 2025
…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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev tools Exception when click interaction with Widget Inspector or Flutter Sidebar itens

3 participants