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 S4457 FP: When argument check is after async code #6449

Closed
paulhickman-a365 opened this issue Nov 25, 2022 · 2 comments · Fixed by #6624
Closed

Fix S4457 FP: When argument check is after async code #6449

paulhickman-a365 opened this issue Nov 25, 2022 · 2 comments · Fixed by #6624
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Milestone

Comments

@paulhickman-a365
Copy link

Description

In Sonar Analyzer version 8.49, the following code, the method HasS4457Async erroneously raises S4457, whereas this does not happen for the method NoS4457Async

The method cannot be split to do the validation before the async code as the validation relies on the result of the async code.

In Sonar Analyzer version 8.48, it doesn't cause S4457.

Repro steps

    public class Class1
    {
        public Task<int[]> CheckAsync() => Task.FromResult(new int[] { 1 });
        public Task<int> Check2Async() => Task.FromResult(1);

        public async Task HasS4457Async(int request)
        {
            var identifierType = (await CheckAsync()).FirstOrDefault(x => x == request);
            if (identifierType == 0) throw new ArgumentException("message");
        }

        public async Task NoS4457Async(int request)
        {
            var identifierType = await Check2Async();
            if (identifierType != request) throw new ArgumentException("message");
        }
    }

Expected behavior

No warning

Actual behavior

Warning S4457

Known workarounds

Downgrade to 8.48 or suppress the warning

Related information

  • Project Type NET Standard 2.1 class library
  • Visual Studio 16.4.1
  • SonarScanner for .NET version 8.49.8.49.0.57237
  • Windows Server 2022
@mary-georgiou-sonarsource
Copy link
Contributor

Thank you for opening this issue, @paulhickman-a365. Your feedback helps us improve our products. We will look at it as soon as possible. After we confirm the issue, we will add labels and put it in our backlog.

@gregory-paidis-sonarsource gregory-paidis-sonarsource added Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be. labels Jan 12, 2023
@github-actions github-actions bot added this to Review in progress in Best Kanban Jan 12, 2023
@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Jan 23, 2023
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Jan 26, 2023
Best Kanban automation moved this from Review in progress to Validate Peach Jan 26, 2023
@gregory-paidis-sonarsource
Copy link
Contributor

Hello @paulhickman-a365, thanks for the feedback, very nice catch.

The necessary work has been completed and this FP will be resolved after the next release.

@gregory-paidis-sonarsource gregory-paidis-sonarsource moved this from Validate Peach to Done in Best Kanban Jan 27, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added this to the 8.52 milestone Jan 31, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title S4457 False positive when argument check is after async code Fix S4457 FP: When argument check is after async code Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

5 participants