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 S2952 FN/FP: FNs on conditional invocation and FPs on additional disposal #6229

Closed
martin-strecker-sonarsource opened this issue Oct 19, 2022 · 1 comment · Fixed by #6230
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@martin-strecker-sonarsource
Copy link
Contributor

Rule S2952 does not report on these kinds of invocations (from the sample of the rule):

  this?.fs?.Dispose(); // FN
  this.fs?.Dispose();  // FN
  fs?.Dispose();       // FN
  this!.fs?.Dispose(); // FN

Rule S2952 Does report in this case, while it shouldn't

  public void Cleanup() => fs.Dispose(); // FP: We should not report in this case as the disposal is taking place in Dispose() too
  public void Dispose() => fs.Dispose();

Originally reported by https://discuss.sonarsource.com/t/11777

@martin-strecker-sonarsource martin-strecker-sonarsource added Type: False Positive Rule IS triggered when it shouldn't be. Type: False Negative Rule is NOT triggered when it should be. Area: C# C# rules related issues. labels Oct 19, 2022
@github-actions github-actions bot added this to False Positive in Backlog Oct 19, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource removed the Type: False Negative Rule is NOT triggered when it should be. label Oct 21, 2022
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Feb 16, 2023
@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Feb 17, 2023
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Feb 17, 2023
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Feb 17, 2023
@martin-strecker-sonarsource martin-strecker-sonarsource changed the title FN/FP S2952: FNs on some Invocation kinds and FP on additional disposal Fix S2952 FN/FP: FNs on some Invocation kinds and FP on additional disposal Feb 21, 2023
Best Kanban automation moved this from Review approved to Validate Peach Feb 21, 2023
@martin-strecker-sonarsource martin-strecker-sonarsource added this to the 8.54 milestone Feb 21, 2023
@martin-strecker-sonarsource martin-strecker-sonarsource changed the title Fix S2952 FN/FP: FNs on some Invocation kinds and FP on additional disposal Fix S2952 FN/FP: FNs on conditional invocation and FPs on additional disposal Feb 21, 2023
@martin-strecker-sonarsource
Copy link
Contributor Author

Peach validation revealed some FPs:

  • Disposed in virtual Dispose(bool disposing) of the dispose pattern
  • Diposed in DisposeAsync
  • Disposal delegated in Dispose to another method.

I created a ticket for the first two patterns #6782

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
Backlog
  
False Positive
3 participants