I have the following block of code that fortify is warning about derefrencing a null pointer (Warning occurs at the highlighted section of code).
Is this a false positive? It's checking to see if it is null right where the warning is occurring.
Update: Added a little more of the code. We are checking before hand to make sure displayAttribute isn't null. Could it be because the IsNotNull() is an extension method?
The warning is that displayAttribute
itself may be null
not Name
. If it is then the access of the Name
property will cause a NullReferenceException
. Given that displayAttribute
is explicitly checked for null
just below the warning it seems that the warning is valid
EDIT
It looks like you are using an extension method to validate that the attribute is not null
. It seems rather counterintuitive to use an extension method this way. The analysis engine seems to agree with me as it can't deduce that this is what you're doing here.
So yes you could ignore the warning here but why do that? Why not just do a normal displayAttribute != null
check so both developers and analysis engines can more easily deduce what your code is actually doing?