Correct way to handle enumerable operations + NotNull?

Nearly every place that I use a LINQ operator on my enumerables, I get a complaint about NotNull from ReSharper. For example:

   var arr = new[] { "a", "b", "c" };
   var x = arr.Select(a => a.ToUpper());

ReSharper will flag the "a" in a.ToUpper as a possible System.NullReferenceException.

I use the Enumerable operators often, and so I have these warnings all over my code. I would mark them as Hint instead of Warning except that I want the NotNull checking on parameters into functions.

What is the best solution for this problem? What do you guys at JetBrains do in this situation?

(Note that I do not want to use the comment-based disable/restore feature. That has a super verbose syntax that would make my code very noisy, considering how many places I use these operators.)

2 comments
Comment actions Permalink

Hello Scott,

I'm afraid I wasn't able to reproduce the 'Possible NullReferenceException'
warning on the sample you've provided. Could you please attach a small sample
solution which would exhibit this warning? Thank you!

Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Nearly every place that I use a LINQ operator on my enumerables, I get
a complaint about NotNull from ReSharper. For example:

var arr = new[] { "a", "b", "c" };
var x = arr.Select(a => a.ToUpper());
ReSharper will flag the "a" in a.ToUpper as a possible
System.NullReferenceException.

I use the Enumerable operators often, and so I have these warnings all
over my code. I would mark them as Hint instead of Warning except that
I want the NotNull checking on parameters into functions.

What is the best solution for this problem? What do you guys at
JetBrains do in this situation?

(Note that I do not want to use the comment-based disable/restore
feature. That has a super verbose syntax that would make my code very
noisy, considering how many places I use these operators.)

---
Original message URL:
http://devnet.jetbrains.net/message/5273656#5273656



0
Comment actions Permalink

How strange, it is no longer reproducing for me either. I will try to get a more solid repro case.

0

Please sign in to leave a comment.