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

New analyzer: unreliable null check #39

Open
ronnygunawan opened this issue Feb 14, 2021 · 0 comments
Open

New analyzer: unreliable null check #39

ronnygunawan opened this issue Feb 14, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ronnygunawan
Copy link
Owner

ronnygunawan commented Feb 14, 2021

A null check is unreliable when:

  1. Checked variable is a mutable field or a mutable property
  2. The value is read again after the null check
  3. No new local was introduced before the value is read again.
  4. Value is written somewhere else
class C {
    string? S;
    List<string> L = new();
    void M() {
        if (S is null) return;
        L.Add(S); // Null check was unreliable
    }
    void N() {
        S = null;
    }
}
@ronnygunawan ronnygunawan added the enhancement New feature or request label Feb 14, 2021
@ronnygunawan ronnygunawan self-assigned this Feb 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant