Parameter usage in local method not detected

Template for a good false-positive report, formatted with Markdown:

  • versions used: SonarQube 8.4.1
private async Task<HttpResponseMessage> SendAsync(HttpMethod method, string apiFormat, params object[] formatters)
{
    async Task<HttpResponseMessage> sendAsync()
    {
        var request = new HttpRequestMessage
        {
            Method = method,
            RequestUri = new Uri(string.Format(apiFormat, formatters.Prepend(_sonarQubeConfigAdress).ToArray()))
        };
        SetRequestHeader(request);
        return await _httpClient.SendAsync(request);
    }

    var response = await Policy
        .HandleResult<HttpResponseMessage>(m => m.StatusCode == HttpStatusCode.GatewayTimeout)
        .WaitAndRetryAsync(5, retryCount => TimeSpan.FromMilliseconds(5),
            onRetry: (httpResponse, timeSpan, retryCount, context) =>
            _logger.LogWarning("Gateway timed out {0} times for request {1}", retryCount, httpResponse.Result.RequestMessage.RequestUri))
        .ExecuteAsync(sendAsync);
    if (!response.IsSuccessStatusCode)
    {
        _logger.LogError("Got unexpected status {0} for request {1} with message: '{2}'",
            response.StatusCode, response.RequestMessage.RequestUri, await response.Content.ReadAsStringAsync());
    }
    response.EnsureSuccessStatusCode();
    return response;
}

See above example. The usage of the parameters method, apiFormat and formatters in the method-local method sendAsync are not detected by sonarqube resulting in ‘csharpsquid:S1172’ remove this parameter whose usage is ignored issues on analysis.

Hi @Rouke.Broersma.IS,

Thank you for reporting this case, I can confirm it as False Positive. We already have a similar case with the same root cause reported in this issue that you can track.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.