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 S1854 FPs: Improve catch block links #4949

Closed
pavel-mikula-sonarsource opened this issue Oct 4, 2021 · 1 comment · Fixed by #5529
Closed

Fix S1854 FPs: Improve catch block links #4949

pavel-mikula-sonarsource opened this issue Oct 4, 2021 · 1 comment · Fixed by #5529
Assignees
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE 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

Similar to #4948

Roslyn LVA needs to be updated for better predecessors/successors computation.

catch should link to all blocks in try to propagate LiveIn through the loop.

public void TryReturns_Loop()
{
    var counter = 0;
    while (counter < 5)
    {
        counter++;  // Noncompliant FP related to LVA
        try
        {
            SomethingThatCanThrow();
            return;
        }
        catch (TimeoutException)
        {
            // Continue loop to the next try
        }
    }
}
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. labels Oct 4, 2021
@jairbubbles
Copy link

I had a similar FP on my side, I'm pasting my example but I'm pretty sure it's the same:

private static string ReadWithRetry(string filePath, int maxRetryCount = 3)
{
    int count = 0;
    while (count++ < maxRetryCount) // S1854 Remove this useless assignment to local variable 'count'
    {
        try
        {
            return File.ReadAllText(filePath);
        }
        catch (Exception)
        {
            Thread.Sleep(100);
        }
    }

    return String.Empty;
}

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. Area: CFG/SE CFG and SE 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.

3 participants