[301] NRE
Maybe these are in progress from the comments made in 300, but 301 gives
the NRE below...
private static void Initialiser(object sender, InitialiserEventArgs e)
{
if (e.NewObject is TransformPackage && e.CallingObject is Model)
{
Model model = e.CallingObject as Model;
TransformPackage package = e.NewObject as TransformPackage;
// NRE warning both model and package below.
int order = model.GetNextOrder();
package.Order = order;
package.ParentPackage.SingleItem = model;
}
}
Please sign in to leave a comment.
Frankly speaking, NRE analysis is quite right here
1) Formal analysis algorithm cannot be sure that subsequential calls to
property (say, e.NewObject) returns the same value
2) After checking type by 'is' expression, it is a good idea to use direct
cast to checked type. Otherwise, if you do use 'as' expression, the 'null'
result is expected
--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Sean Kearon" <no@spam.org> wrote in message
news:adc66bd2b8c8c8d39d473f687e@news.jetbrains.com...
>
>
>
Sean Kearon schrieb:
Which is correct.
If the e.CallingObject is not from type Model, then model ist null.
The same with package.
Regards
Albert
Thanks Eugene.....
Good point - it's a case here of R# improving my code.....which is always
a good thing ;)
An opportunity to use the "Convert to direct cast" context action.....if
there was one ;)
Regards
Sean