Why this matters
Copy-pasting code can lead to errors where getters or setters access the wrong fields. Always verify that properties interact with the expected fields.
Copy-pasting code can lead to errors where getters or setters access the wrong fields. Always verify that properties interact with the expected fields.
Copy-pasting code can lead to errors where getters or setters access the wrong fields. Always verify that properties interact with the expected fields.
Side-by-side examples engineers can pattern-match during review.
class A
{
private int x;
private int y;
public int X
{
get { return x; }
set { x = value; }
}
public int Y
{
get { return x; } // Noncompliant: field 'y' is not used in the return value
set { x = value; } // Noncompliant: field 'y' is not updated
}
}class A
{
private int x;
private int y;
public int X
{
get { return x; }
set { x = value; }
}
public int Y
{
get { return y; }
set { y = value; }
}
}class A
{
private int x;
private int y;
public int X
{
get { return x; }
set { x = value; }
}
public int Y
{
get { return x; } // Noncompliant: field 'y' is not used in the return value
set { x = value; } // Noncompliant: field 'y' is not updated
}
}class A
{
private int x;
private int y;
public int X
{
get { return x; }
set { x = value; }
}
public int Y
{
get { return y; }
set { y = value; }
}
}From the same buckets as this rule.