3

Consider this example

var task =Task.Factory.StartNew(()=>Console.WriteLine("test"));

task.ContinueWith(antecendent =>
        {
            ExceptionProcessor.HandleError(task.Exception.Flatten());
        }, TaskContinuationOptions.OnlyOnFaulted);

In this example resharper predicts that there is a possible null pointer exception in task.Exception.Flatten() as it assumes task.Exception could be null .

But for all realistic scenarios it is not going to be null as the parameter TaskContinuationOptions.OnlyOnFaulted ensures the method gets called only when an exception occurs.

So How do I tell Resharper to ignore all similar warnings ?

svick
  • 236,525
  • 50
  • 385
  • 514
Vasudevan Kannan
  • 911
  • 2
  • 7
  • 22

2 Answers2

3

I think you have several options:

  1. Ignore the warning in this instance.
  2. Lower the severity of all “Posible NullReferenceException” to something like Hint, or even Do not show.
  3. Disable this instance of the warning by a comment.
  4. Pretend ReSharper is right and add the null check.

I don't like #4, you would be making your code less readable just so that ReSharper is happy. I also don't like #3, that could pollute your code with those comments a lot. #2 is better, but I think #1 is the best option: “Posible NullReferenceException” will always have false positives and so you should use it as a guidance: “be careful here, something may be wrong”, not as a strict “you have to fix this”.

svick
  • 236,525
  • 50
  • 385
  • 514
  • I agree with all your comments , Ignoring the warning seems the best possible case as of now .But the problem is then you cannot distinguish the real cases where a null check is missing and the false positives – Vasudevan Kannan Jun 22 '12 at 19:16
  • Yeah, I know, but I don't know any better solution. – svick Jun 22 '12 at 19:26
3

Resharper support team has accepted this as a bug and it can be tracked here http://youtrack.jetbrains.com/issue/RSRP-316492

Vasudevan Kannan
  • 911
  • 2
  • 7
  • 22