Getters and Setters without private variable

Help needed to add a rule for this kind of bug in the product.

Problem statement: Public property without a private variable used the Getters and Setters. Given the example below that “Name” is used as property name and also local variable, but not declared the local variable. In this case, when we assign the data to this property, it goes as recursive call infinitely and finally gets time-out from the service.

public string Name
{
  get
  {
    return Name;
  }
  set
  {
    Name = value;
  }
}

This is the code in C#. Do you have any rule already to capture for this bug. If you have the rule, please share the details.

Hi @geetha_ganesan,

We have a rule https://rules.sonarsource.com/csharp/RSPEC-2190 that get’s triggered on your getter warning you about infinite recursion.

Same rule should trigger for the setter as well. I’ve added this issue to improve S2190.