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 FP: Value used after catch #9467

Closed
pavel-mikula-sonarsource opened this issue Jun 26, 2024 · 1 comment
Closed

Fix S1854 FP: Value used after catch #9467

pavel-mikula-sonarsource opened this issue Jun 26, 2024 · 1 comment
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.

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

pavel-mikula-sonarsource commented Jun 26, 2024

Removing the if will make this work as expected.
The block before try should already be connected to catch block. It's not clear why it produces a FP

    public int ReadAfterCatchAll_WithType(bool condition)
    {
        var value = 100;    // Noncompliant FP, used after catch all
        try
        {
            CanThrow();
            if (condition)
            {
                CanThrow();
            }
            value = 200;
        }
        catch (Exception exc)
        {
        }
        return value;
    }

This likely has the same root cause as

    public void ReadInCatch_WithBranching(bool condition)
    {
        var value = 100;    // Noncompliant FP, used in catch
        try
        {
            value = CanThrow();
            if (condition)
            {
                CanThrow();
            }
            else
            {
                CanThrow();
            }
        }
        catch
        {
            Log(value);
        }
    }
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title Fix S854 FP: Value used after catch Fix S1854 FP: Value used after catch Jun 26, 2024
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Area: CFG/SE CFG and SE related issues. Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. Sprint: LVA labels Jun 26, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource added this to the 9.30 milestone Jul 15, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource modified the milestones: 9.30, 9.31 Jul 23, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource removed this from the 9.31 milestone Jul 24, 2024
@mary-georgiou-sonarsource
Copy link
Contributor

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