CSharpAnalyzers / ExceptionalReSharper

Extension for ReSharper which analyzes thrown and documented C# exceptions and suggests improvements
Microsoft Public License
124 stars 30 forks source link

False ArgumentNullException #18

Open RicoSuter opened 8 years ago

RicoSuter commented 8 years ago

Exceptional says that this code can give ArgumentNullException:

if (foo != null)
    a = foo.FirstOrDefault();

https://exceptional.codeplex.com/workitem/8337

cmeeren commented 7 years ago

This also goes for examples like these:

catch (SomeException ex)
{
    ex.Data.Add("Faulting file", filename);
    throw;
}

Here, it warns of ArgumentNullException, even though "Faulting File" is clearly not null (being a string literal). In general, more intelligent null checking would benefit Exceptional.

cmeeren commented 7 years ago

In general, would it be possible to hook into Resharper's more sophisticated nullability analysis? It's very powerful, especially when using their Resharper's annotations framework.

RicoSuter commented 7 years ago

At the moment, exceptional does not use ReSharper's flow analysis API/tools... the big question for me is: Shouldn't we start a new analyzer project based on Roslyn to target a much bigger audience? I.e. port Exceptional to Roslyn?

cmeeren commented 7 years ago

Another one:

foreach (object key in Data.Keys)
{
    object value = Data[key];
    // ...
}

The getter warns of a possible ArgumentNullException even though we are iterating through the keys of the dict.