False positive for S4275 Getters and setters should access the expected fields False postive

Seems something has changed in the processing for S4275 “recently” (between January 18th and this morning).

We have code that is loosely like:

Public Class A
    Private _chargeId as Integer
    Public Overrideable Property ChargeId As Integer
        Get
            Return _chargeId
        End Get
        Set(value As Integer)
            If (value <> _chargeId)
                _chargeId = value ' strictly speaking, we're doing other validation, but a scenario where auto properties aren't a solution
            End If
        End Set
    End Propery
End Class

Public Class B
    Inherits A

    Public Overrides Property ChargeId As Integer
        Get ' Refactor this getter so that it actually refers to the field '_chargeID'.
            Return If(SomeCondition, MyBase.ChargeId, 1234)
        End Get
        Set(value As Integer) ' Refactor this setter so that it actually refers to the field '_chargeID'
            MyBase.ChargeId = value
        End Set
    End Property
End Class

So we’re overriding a virtual method that doesn’t have access to _chargeId, yet the derived class class is told it should reference it.

As an aside, this also doesn’t show up in Visual Studio; but only when doing analysis on a build with Azure DevOps…

Hi @RowlandShaw,

thanks a lot for your feedback. I can confirm the false positive, I’ve added an issue and you can follow the progress here: Rule S4275: false positive on Visual Basic when using property overload · Issue #5336 · SonarSource/sonar-dotnet · GitHub

1 Like