Old sonar violations are marked as new violations inconsistently

sonarqube

(Rama Krishna) #1

I have squid:S134 violation in my existing code.

I have changed most of the conditional statements with out fixing them and the violations remained same as old ones.

When I changed the conditions along with some other code changes in same file then sonar is flagging my old violation as new ones.

Please find attached screen shots and let me know a pattern which sonar follows to convert old violations as new ones.

Case 1: I have a code with control flow violation as below and ran initial Sonar build

Case 2: Changed the existing conditions and ran another build which went fine

Case 3: Made few more changes to code sonar changed old violation to new

Question is when I have modified all conditions as in case 2, it didn’t created any new issues. But in case 3, when I have modified condition along with some other changes in file is marking my old violation as new one.

Can you help me find how this marking of old violation as new violation is happening


(G Ann Campbell) #2

Hi,

This is happening because the issue matching algorithm can’t tell that the issue raised in the most recent analysis is the same as the one raised initially.

Looking closely, I see that the issue was initially raised

43    if (num > num4) {

By the last analysis, this has changed to

54    if (somethingICantRead && num > num4) {

Issue matching takes into account rule, line number, and line hash. By your third analysis, these things have changed enough that it’s no longer recognized as the same issue, so the old issue is closed, and a new issue is raised (it’s not actually re-dating your original issue).

 
HTH,
Ann


(Rama Krishna) #3

Thank you for the response…