Why null check not working before method call?

I have one method in c#. Before calling method i checked not null condition of the parameter. But inside the method i didn’t check null condition. why it’s showing as bug? because i checked before calling a function. both the functions are in same file?

Example:

int[] data=null;

public void F1()
{
    if(data != null)
       F2(data);
}
public void F2(int[] p1)
{
   var res=p1[0];
}

I’ve moved your post to the category on reporting false-positives.

Make sure to read this post before raising a thread here:

We’re missing some information (like the specific rule ID)

CSharpsquid:S2259

Hi @Anantham

Welcome to the forum. Please read our rules.

Be patient

  • Wait a few days before bumping a topic that hasn’t received a response.

Hello @Anantham

Thank you for reaching out to us.
For the time being we don’t support cross method analysis. So, our analyzer does not know that a null check was done before the invocation.
On the other hand I would not call this a false positive, because there might be other invocations of F2 without the null check in place. I suggest to move the check inside F2.

All the best,
Čaba

Thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.