Skip to content

Proposal: debugNeedsPaint, debugNeedsLayout, debugNeedsCompositedLayerUpdate crash in release mode instead of returning gracefully #183696

Description

@futpib

Steps to reproduce

  1. Access RenderObject.debugNeedsPaint (or debugNeedsLayout, debugNeedsCompositedLayerUpdate) in app code — e.g. to guard a RenderRepaintBoundary.toImage() call
  2. Build in release mode
  3. The getter throws LateInitializationError: Local 'result' has not been initialized

Expected behavior

These properties should return false in release mode, like debugNeedsSemanticsUpdate already does:

// debugNeedsSemanticsUpdate — correct, works in release:
bool get debugNeedsSemanticsUpdate {
  if (kReleaseMode) {
    return false;
  }
  return _semantics.parentDataDirty;
}

// debugNeedsPaint — crashes in release:
bool get debugNeedsPaint {
  late bool result;
  assert(() {
    result = _needsPaint;
    return true;
  }());
  return result;  // LateInitializationError in release!
}

Proposal

Apply the same kReleaseMode guard to debugNeedsPaint, debugNeedsLayout, and debugNeedsCompositedLayerUpdate:

bool get debugNeedsPaint {
  if (kReleaseMode) {
    return false;
  }
  return _needsPaint;
}

Alternatively, annotate them with @visibleForTesting so the analyzer warns when they're used outside of tests.

Context

debugNeedsPaint, debugNeedsLayout, and debugNeedsCompositedLayerUpdate all use the late bool result + assert() pattern, while debugNeedsSemanticsUpdate in the same class uses a kReleaseMode guard. The inconsistency is the issue — a developer seeing one debug* property work safely might reasonably expect the others to behave the same way.

Flutter version

Flutter 3.41.2 • channel stable
Framework • revision 90673a4eef
Engine • hash d96704abcce17ff165bbef9d77123407ef961017

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions