R# 4.0.736.4 One Line - Two question

For the following line of C# code R# reports 1 Problem and 1 suggestion.

string myName = WindowsIdentity.GetCurrent().Name;

The problem should be: That "WindowsIdentity.GetCurrent().Name" generates a System.NullReferenceException. Is that really possible ? I believe no!

And why suggest R# to use a var declaration instead of string declaration.

regards
HP

4 comments
Comment actions Permalink

There are a number of library calls which 4.0 mistakenly thinks can return null at the moment.

I file bugs on them when I encounter them.

The obsesion with 'var' is under debate in another thread. You can turn warnings/suggestions off from the alt-enter menu now.

Will

0
Comment actions Permalink

Hello,

For the following line of C# code R# reports 1 Problem and 1
suggestion.

string myName = WindowsIdentity.GetCurrent().Name;

The problem should be: That "WindowsIdentity.GetCurrent().Name"
generates a System.NullReferenceException. Is that really possible ? I
believe no!


It's not a matter of belief, it's a matter of implementation. At a glance,
it's technically possible for GetCurrent() to return Null. Have you checked
the source code?

R# cannot judge the probability of the event, of course. There are just code
paths that would return Null.

And why suggest R# to use a var declaration instead of string
declaration.


Is it really a suggestion (a green wave under the "string" keyword)?


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0
Comment actions Permalink

I tend to think the sheer number of inquiries about the 'var' suggestions
will eventually persuade the R# team to make them all hints by default. I'm
sure there are countless developers out there using VS2008 who know nothing
about the new C# 3.0 language enhancements, many of whom will think "Huh,
'var'? Why does R# think I'm writing JavaScript?"

Mike

"Will Dean" <resharper@indcomp.co.uk> wrote in message
news:13386753.1203939109163.JavaMail.itn@is.intellij.net...

There are a number of library calls which 4.0 mistakenly thinks can return
null at the moment.

>

I file bugs on them when I encounter them.

>

The obsesion with 'var' is under debate in another thread. You can turn
warnings/suggestions off from the alt-enter menu now.

>

Will


0
Comment actions Permalink

Actually the comment for GetCurrent() says:
"Returns a ]]> object that represents the current Windows user."

But you are right, a lot of the other reports here can be null.

0

Please sign in to leave a comment.