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 S1226 FP: Parameters wrongly considered as unread before reassignment #2555

Closed
saciervo opened this issue Aug 6, 2019 · 0 comments · Fixed by #2843
Closed

Fix S1226 FP: Parameters wrongly considered as unread before reassignment #2555

saciervo opened this issue Aug 6, 2019 · 0 comments · Fixed by #2843
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Milestone

Comments

@saciervo
Copy link

saciervo commented Aug 6, 2019

Description

According to RSPEC-1226

parameters should be [...] at least read before reassignment

Is null-checking or passing a parameter to a method like string.IsNullOrWhiteSpace(text) not reading the parameter?

Repro steps

public class Class1
{
    public void Foo(string text)
    {
        if (string.IsNullOrWhiteSpace(text))
        {
            text = "(empty)";
        }

        Bar(text);
    }

    private void Bar(string text)
    {
        // Do something
    }
}

Expected behavior

The variable text has been used before it was assigned. So this code should be compliant.

Actual behavior

The code is marked as non-compliant.

Known workarounds

Use the parameter to assign a local variable.

Related information

  • SonarC# Version: 7.15
  • Visual Studio Version: 16.2.0 (VS2019)
@andrei-epure-sonarsource andrei-epure-sonarsource added this to the Support milestone Sep 26, 2019
costin-zaharia-sonarsource added a commit that referenced this issue Nov 6, 2019
@costin-zaharia-sonarsource costin-zaharia-sonarsource added Area: C# C# rules related issues. Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. labels Nov 6, 2019
@costin-zaharia-sonarsource costin-zaharia-sonarsource removed their assignment Nov 6, 2019
@christophe-zurn-sonarsource christophe-zurn-sonarsource modified the milestones: Support, 8.1 Nov 25, 2019
@pavel-mikula-sonarsource pavel-mikula-sonarsource moved this from To do to In progress in Best Kanban Nov 26, 2019
@pavel-mikula-sonarsource pavel-mikula-sonarsource moved this from In progress to Review in progress in Best Kanban Nov 27, 2019
@pavel-mikula-sonarsource pavel-mikula-sonarsource changed the title S1226: Clarification about the meaning of "reading" the parameter Fix S1226 FP: Parameters wrongly considered as unread before reassignment Nov 28, 2019
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Area: VB.NET VB.NET rules related issues. and removed Area: Rules labels Nov 28, 2019
@christophe-zurn-sonarsource christophe-zurn-sonarsource moved this from Review in progress to Reviewer approved in Best Kanban Dec 2, 2019
Best Kanban automation moved this from Reviewer approved to Done Dec 2, 2019
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: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

5 participants