---
title: Avoid getters that recursively return themselves
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid getters that recursively return themselves
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Avoid getters that recursively return themselves

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `dart-code-quality/recursive-getters`

**Language:** Dart

**Severity:** Warning

**Category:** Code Style

## Description{% #description %}

A getter whose body only returns itself recurses forever and throws a stack overflow at runtime, for example `int get value => value;`. This almost always means a backing field was forgotten. Return the backing field or a computed value instead of the getter itself.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```dart
class Broken {
  int get value => value;

  String get name {
    return name;
  }

  int get a {
  return this.a;
  }

  int get total => this.total;
}

int get count => count;
```

## Compliant Code Examples{% #compliant-code-examples %}

```dart
class Example {
  int _value = 0;
  int a = 1;
  int b = 2;

  int get value => _value;

  int get total => a + b;

  String get label {
    return _label;
  }

  final String _label = "x";
}

int get answer => 42;
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 