SonarQube are marking the wrong line in our Azure DevOps Pullrequest (PR)

Must-share information (formatted with Markdown):

  • which versions are you using: SonarQube Enterprise 10.5.1
  • how is SonarQube deployed: zip
  • what are you trying to achieve: Pull Request comment from SonarQube on the wrong linenumber in Azure DevOps Pullrequest (C++/C code), but not in SonarQube where the comment is on the correct line
  • what have you tried so far to achieve this: Configured the SonarQube Project to comment on Azure DevOps Pullrequests. we have also tried re-executing the SonarQube analysis, but are unsure if this is a coverage.xml problem or other problem. Do note that there is a lot of changes in this PR and also lots and lots of comments. From experience this might be an Azure DevOps problem - I personally think its an cosmetical problem, but I understand that our developers find it annoying. Any tips here are welcome.

Azure DevOps PR - there is a marking of line 216:
image

SonarQube Project - there is a marking of line 216
image

SonarQube Project - there is a warning, not sure its correct, but may be the reason if the coverage.xml is the problem. we are not sure

image

We beleive line 216 is the correct line.

Hey there.

What I first find striking is that the PR comment is from August 21st. Has SonarQube analysis run on the most recent commit of the PR?

What I’m thinking is:

  • Analysis was executed, the PR was decorated
  • The file got updated again, and naturally line numbers changed in Azure DevOps representation of the PR
  • Analysis hasn’t be executed since the file was updated

Another way to ask this is: Does the file’s current state in the PR (outside the PR view, just in the repo view) match what is shown in SonarCloud?

Allright, I think our guys have figured out why this issue arises.

  • The problem arises because: SonarQube makes the analysis on the merge-commit that Azure DevOps creates, but Azure DevOps doesn’t show the changes from that in the pull-request.

  • SonarQube GUI shows the code as it looks in the merge-commit. Thats why the comment looks ok in SonarQube.

So, the conclusion is; if there are changes on the main-branch, on top of the pull-request, then SonarQube will miscalculate the line numbers sligtly (in the PR), depending on the amount of added or removed lines of code.

(Hopefully I’ve translated this correctly - I hope that make sense. :slight_smile: )

Is this something that could be fixed in a future version or is it by design?

Thanks for looking deeper into it @jensmadsen! If that’s the case, it sure seems we need to look into it a bit closer… I’ve flagged this for attention.