Hi,
I'm evaluating SonarQube for the company I work for. It looks very good but I found two families of false positive occurring frequently across the code I tested. I've been able to reproduce the first one on SonarCloud, see details below. I wonder if you can give me an idea of how long it might be before this is fixed or otherwise point out what I'm doing wrong which means we're getting this?
Setup
C#, Sonar Scanner for MSBuild 4.0.2.892, Running on Windows 10, using the SonarC# analyser on SonarCloud and also SonarQube 6.7.1 LTS + SonarC# 6.7 running on a Windows server.
In both cases the MSBuild was MSBuild 15 from Visual Studio 2017.
I ran exactly the commands SonarCloud suggested:
SonarQube.Scanner.MSBuild.exe begin /k:"SonarQubeTest" /o:"djn24-github" /d:sonar.host.url="
https://sonarcloud.io" /d:sonar.login="<<my token>>"
"c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" /t:Rebuild SonarQubeTest\SonarQubeTest.sln
SonarQube.Scanner.MSBuild.exe end /d:sonar.login="<<my token>>"
Problem
Here's the code:
public bool AreFullyQualified(string[] files)
{
bool anyPathRooted = false;
bool allPathsRooted = true;
foreach (var file in files)
{
if (Path.IsPathRooted(file))
{
anyPathRooted = true;
}
else
{
allPathsRooted = false;
}
}
if (anyPathRooted && !allPathsRooted)
{
throw new InvalidOperationException("Paths must be all rooted or all unrooted");
}
return allPathsRooted;
}
SonarC# reports "Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed" on "if (anyPathRooted && !allPathRooted)".
It is possible for any but not all paths to be rooted, if the IsPathRooted check passes for some but not all paths.
We found similar patterns in several places in the code which I think are all the same problem, this was just the easiest to extract from the code.
Thanks for your time,
Dominic