S3928 with local function - false positive or expected behavior

The following code raises warning S3928: The parameter name 'theParameter' is not declared in the argument list. with SonarAnalyzer version

public async Task MethodAsync(string theParameter)

    await SomeAsyncOperation(theParameter);

    void CheckParameters()
        if (theParameter == null)
             throw new ArgumentNullException(nameof(theParameter)); // S3928

I’m unsure whether this is false positive or expected behavior. I guess it is false positive.

BTW: The local function is introduced to fix S4457.

1 Like

Hi @lg2de, thanks for your feedback.

This is now considered a true positive (parameter of another function/method). We have it internally documented here: sonar-dotnet/CheckArgumentException.cs at master · SonarSource/sonar-dotnet · GitHub

That being said, I will trigger a discussion in the team so we might reconsider this pattern and add it as an exception.