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

S2259 FP: Null conditional combined with null coalescing #4537

Closed
przemyslaw-piescik opened this issue Jun 10, 2021 · 2 comments · Fixed by #6140
Closed

S2259 FP: Null conditional combined with null coalescing #4537

przemyslaw-piescik opened this issue Jun 10, 2021 · 2 comments · Fixed by #6140
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.
Milestone

Comments

@przemyslaw-piescik
Copy link

Description

S2259 is incorrectly reported when using null conditional with null coalescing operator.

Repro steps

        private void Sample()
        {
            string someString = null;

            if (!someString?.Contains("a") ?? true)
                Console.WriteLine("It's null or doesn't contain 'a'");
            else
                Console.WriteLine(someString.Length); //S2259 reported here
        }

Expected behavior

S2259 should not be reported in this case.

Actual behavior

S2259 is reported.

@pavel-mikula-sonarsource
Copy link
Contributor

Hi @przemyslaw-piescik ,

Thank you for reporting this case, I can confirm it as False Positive. We already have similar issue reported in #2528 with the same root cause that you can follow. I'll close this one.

@pavel-mikula-sonarsource
Copy link
Contributor

pavel-mikula-sonarsource commented Jun 24, 2021

I'll actually keep this one opened, as it's isolated from the integer constraint issue reported in the other one.

@pavel-mikula-sonarsource pavel-mikula-sonarsource added Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Type: False Positive Rule IS triggered when it shouldn't be. labels Jun 24, 2021
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. and removed Type: False Positive Rule IS triggered when it shouldn't be. labels Jun 25, 2021
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 8.43 milestone Jul 18, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource modified the milestones: 8.43, 8.44 Jul 29, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource removed this from the 8.44 milestone Aug 8, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 8.45 milestone Aug 22, 2022
@pavel-mikula-sonarsource pavel-mikula-sonarsource modified the milestones: 8.45, 8.46 Sep 14, 2022
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