Closed rodchenkov closed 1 week ago
Hey @rodchenkov , I confirm that this is a false positive. I added it to our backlog, where it will be taken care of along other S2589 FPs soon. Thanks for raising this.
Something to add, implementation-wise:
In the expression first.AddRange(second)
, second is cleared of CollectionConstraint
because it's used as Argument
.
This might be problematic when trying to establish when AddRange
should influence the CollectionConstraint
of first
.
I also ran into this issue, wouldn't it be better to disable this rule for now until it's fixed?
Here's another simple scenario to reproduce it:
namespace SonarQubeRulesTest;
internal class Program
{
static void Main(string[] args)
{
var theList = new List<int>();
theList.AddRange(GetNumbers());
if (theList.Any())
{
Console.WriteLine("Numbers found");
}
else
{
Console.WriteLine("No numbers found");
}
}
public static IEnumerable<int> GetNumbers()
{
return new List<int> { };
}
}
Another user report
Description
I have warning S2589 for
list.Count == 0
but I'm sure it is false positive.Repro steps
Please find code below:
Expected behavior
No warning S2589 for line
if (authorizeAttributes.Count == 0) return;
Actual behavior
Warning S2589 for line
if (authorizeAttributes.Count == 0) return;
Known workarounds
Only suppress warning
Related information