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 S2259: "Null pointer dereference" false positive when fields qualified with 'this' are assigned and then read #538

Closed
valhristov opened this issue Jul 5, 2017 · 0 comments
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@valhristov
Copy link
Contributor

Description

An issue is raised on this._hello.Contains("Hello") and should not be.

Repro steps

class HelloWorld
{
    private string _hello;

    public string DoSomething()
    {
        return GetHello();
    }

    private string GetHello()
    {
        if (this._hello == null)
        {
            this._hello = null;
        }
        else
        {
            this._hello = "Hello";
        }

        if (this._hello != null && this._hello.Contains("Hello"))
        {
            return _hello;
        }
        return null;
    }
}

Expected behavior

No issue is raised.

Related information

  • SonarC# Version 6.1
@valhristov valhristov added Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. labels Jul 5, 2017
@valhristov valhristov added this to the near-future milestone Jul 5, 2017
@Evangelink Evangelink modified the milestones: 6.3, near-future Jul 14, 2017
@Evangelink Evangelink modified the milestones: 6.4, 6.3 Jul 24, 2017
@valhristov valhristov self-assigned this Aug 3, 2017
@valhristov valhristov changed the title Fix S2259: "Null pointer dereference" false positive in attached code Fix S2259: "Null pointer dereference" false positive when fields qualified with 'this' are assigned and then read Aug 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants