Skip to content

VSSDK006 does not recognize null check in combination with ternary condition #211

@DmitryGaravsky

Description

@DmitryGaravsky

Bug description

A clear and concise description of what the bug is.

  • Version of the vssdk-analyzers: 16.3.14
  • Analyzer rule: VSSDK006
  • Error (exception message, type, and callstack where applicable):

Warning VSSDK006 Check whether the result of GetService calls is null.

To Reproduce

Sample code:

var item = provider.GetService(typeof(EnvDTE.ProjectItem)) as EnvDTE.ProjectItem; // <<< warning here
return (item != null) ? item.ContainingProject : null;

Expected behavior

No error since checking item for null is present.

Additional context

This code works fine:

var item = provider.GetService(typeof(EnvDTE.ProjectItem)) as EnvDTE.ProjectItem; // <<< no warning here
if (item != null)
    return null;
return item.ContainingProject;

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions