Incorrect warning S2583

Please provide

  • Operating system: Windows 11
  • Visual Studio version: 17.9.2
  • SonarLint plugin version:
  • Programming language you’re coding in: C#
  • Is connected mode used: No

And a thorough description of the problem / question:

I have this code where the sonarlint falsely warns me about unreachable code. It says that messageIds.Count is always false

List<int> messageIds = new List<int>();
Handlers.FindAll(h => h.IsTrue).ForEach(h => messageIds.Add(h.MessageID));

if (messageIds.Count > 0) // <-- warned about this condition always being false
  _otherValidList.AddRange(new DIM().GetMessages(messageIds));

Hello @TimBijnen and thanks a lot for reporting this.

I confirm this is a false positive. I’ve added an issue to our backlog which you can track here.