Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S2259 FP: ValidatedNotNullAttribute in extension method #7048

Closed
pavel-mikula-sonarsource opened this issue Apr 6, 2023 · 0 comments · Fixed by #7049
Closed

Fix S2259 FP: ValidatedNotNullAttribute in extension method #7048

pavel-mikula-sonarsource opened this issue Apr 6, 2023 · 0 comments · Fixed by #7049
Assignees
Labels
Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Milestone

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

pavel-mikula-sonarsource commented Apr 6, 2023

When ValidatedNotNullAttribute is used in an extension method, the effect is not recognized by the engine:

    <Extension>
    Public Sub CheckNotNullExtension(Of T)(<ValidatedNotNull> Value As T, Name As String)
        If Value Is Nothing Then Throw New ArgumentNullException(Name)
    End Sub

    Public Sub LogExtension(Value As String)
        Value.CheckNotNullExtension("Value")
        If Value Is Nothing Then
            Console.WriteLine(Value.ToString)  ' Noncompliant FP, this code is not reachable
        End If
    End Sub

because there's different method symbol interpretation of the extension methods:
C#: CheckNotNullExtension(Value, "Value")
VB: Value.CheckNotNulLExtension("Value")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants