R# 4.0.731: Possible 'System.NullReferenceException' warning is not always shown

Hello
 
I have the following code:
 
 
As you can see from the colour coding in the above screencap, ReSharper shows correctly that "request" can possibly throw a System.NullReferenceException but it does not show the same for the next line and in the next line "request.AccountData" can be null as well.
 
Regards
 
Gabriel Lozano-Moran
]]>



Attachment(s):
MissingSystemNullReferenceException.jpg
3 comments
Comment actions Permalink

Hello Gabriel Lozano-Moran,

We show the warning for the first occurence to avoid excessive highlighting.

WBR,
Oleg Stepanov
Senior Whiteboard Operator
JetBrains, Inc.
"Develop with pleasure!"
mailto:oleg.stepanov@jetbrains.com


0
Comment actions Permalink

Hello Oleg

Ah okay thanks for letting me know :) Can this be controlled somewhere from
the options? Is it possible to enable the "excessive" highlighting?

Gabriel Lozano-Moran

"Oleg Stepanov" <oleg.stepanov@jetbrains.com> wrote in message
news:f94546f60ed58ca41397826d824@news.intellij.net...

Hello Gabriel Lozano-Moran,

>

We show the warning for the first occurence to avoid excessive
highlighting.

>

WBR,
Oleg Stepanov
Senior Whiteboard Operator
JetBrains, Inc.
"Develop with pleasure!"
mailto:oleg.stepanov@jetbrains.com

>


0
Comment actions Permalink

Hello Gabriel Lozano-Moran,

Well, that is not about excessive highlighting, actually :)

Consider the code below:

void foo(GetAccountIdRequest request)
{
if (request != null)
ProcessRequest(request);
ProcessData(request.AccountData);
ProcessAddress(request.AccountData.Address);
}

The fact that request can be null is deduced from the fact that you already
checked it for null, but null value could have escaped from the controlling
if.
If ProcessAddress(...) statement is executed it is already known that request
is not null. Because otherwise NullReferenceException would have happened
before.
So request is not null at last statement. What about request.AccountData?
For properties, analsysis cannot be performed in complete manner. If you
put attribute on the property, you will see the warning. You
must specify explicitly, when property value can be null. Otherwise, it is
considered that property may or may not be null and no warning is issued.

Also note, that null reference analysis is quite conservative. If it warning
is issued, then most likely you will have NRE exception. If there is no warning,
you cannot be sure all is safe.


Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


G> Hello Oleg
G>
G> Ah okay thanks for letting me know :) Can this be controlled
G> somewhere from the options? Is it possible to enable the "excessive"
G> highlighting?
G>
G> Gabriel Lozano-Moran
G>
G> "Oleg Stepanov" <oleg.stepanov@jetbrains.com> wrote in message
G> news:f94546f60ed58ca41397826d824@news.intellij.net...
G>
>> Hello Gabriel Lozano-Moran,
>>
>> We show the warning for the first occurence to avoid excessive
>> highlighting.
>>
>> WBR,
>> Oleg Stepanov
>> Senior Whiteboard Operator
>> JetBrains, Inc.
>> "Develop with pleasure!"
>> mailto:oleg.stepanov@jetbrains.com


0

Please sign in to leave a comment.