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 S2583 FP: Variable Set in Catch Block #8378

Closed
groogiam opened this issue Nov 17, 2023 · 3 comments · Fixed by #8444
Closed

Fix S2583 FP: Variable Set in Catch Block #8378

groogiam opened this issue Nov 17, 2023 · 3 comments · Fixed by #8444
Assignees
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Milestone

Comments

@groogiam
Copy link

groogiam commented Nov 17, 2023

Description

S2583 FP Variable Set in Catch Block

Repro steps

var success = true;
try
{
    var result = 100 / DateTime.Now.Second;
}
catch (Exception ex)
{
    success = false;
}
if (success) // FP
{
    Console.WriteLine("Success!");
}

Expected behavior

S2583 should not trigger at success if statement.

Actual behavior

S2583 is triggered at success if statement.

Known workarounds

Please provide a description of any known workarounds.

Related information

  • C#/VB.NET Plugins version Sonarlint 7.4.0.80741
  • Visual Studio version 17.8.0
  • MSBuild / dotnet version 8.0.100
  • SonarScanner for .NET version (if used)
  • Operating System Windows 10
@Tim-Pohlmann
Copy link
Contributor

Hi @groogiam thanks for the report!
I confirm this as an FP. I simplified the example a bit. The problem is, that the analyzer treats the division as a safe operation (which is wrong). We will improve this in the future.

@Tim-Pohlmann Tim-Pohlmann added Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules 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. labels Nov 29, 2023
Tim-Pohlmann added a commit that referenced this issue Nov 29, 2023
@Tim-Pohlmann Tim-Pohlmann added this to the 9.16 milestone Dec 6, 2023
@Tim-Pohlmann Tim-Pohlmann changed the title Fix S2583 FP Variable Set in Catch Block Fix S2583 FP: Variable Set in Catch Block Dec 6, 2023
@Tim-Pohlmann Tim-Pohlmann self-assigned this Dec 6, 2023
@groogiam
Copy link
Author

@Tim-Pohlmann Has this been released in Sonar Lint? I'm still seeing similar false positives to this in my code. Thanks.

@Tim-Pohlmann
Copy link
Contributor

Tim-Pohlmann commented Jan 3, 2024

@groogiam Not yet. It should be in the next release. You can track the relevant issue here.
Alternatively, you can download the newest analyzer (which already contains the fix) directly from Nuget.

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. Area: VB.NET VB.NET rules 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