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

Rule S4581: FN with default and default(Guid) #4459

Closed
csaba-sagi-sonarsource opened this issue May 21, 2021 · 1 comment · Fixed by #5037
Closed

Rule S4581: FN with default and default(Guid) #4459

csaba-sagi-sonarsource opened this issue May 21, 2021 · 1 comment · Fixed by #5037
Assignees
Labels
Area: C# C# rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Milestone

Comments

@csaba-sagi-sonarsource
Copy link
Contributor

Description

No issue is raised if default or default(Guid) is used instead of new Guid().

Repro steps

public void Foo()
{
    var guid = default(Guid); // Noncompliant
    Guid other = default; // Noncompliant
}

Expected behavior

Issue should be raised for both default and default(Guid).

Actual behavior

No issue is raised.

Related information

  • C#/VB.NET Plugins version : 8.22.0.31243
@iCodeSometime
Copy link

iCodeSometime commented Mar 23, 2023

While new Guid() or new() reads ambiguously, default is 100% as clear as Guid.Empty, since it matches the behavior of default anywhere else the keyword can be used.

My first assumption was that this was a false positive issue.
No rationale was given for why the sonar team believes the default keyword is best avoided for only this one type in particular.. IMO this change should be reverted, as it does not provide any additional clarity.

@csaba-sagi-sonarsource

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 Negative Rule is NOT triggered when it should be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants