Search code examples
sonarqubesonarqube-web

Sonarqube incorrect report for duplicated code


I am a newbie to SonarQube and trying to use the tool for measuring my product quality.

In some cases, I found that the duplicated lines is reported incorrectly by SonarQube . The number of lines of code is less than the duplicated lines. How can that be ? Either the count of lines of code is incorrect or the count of duplicated lines is incorrect.

Assuming it could be a problem with my code alone, I visited the demo page of Sonarqube https://sonarqube.com/component_measures/domain/Duplications?id=com.adobe%3Aas3corelib

There as well , I found that one of the cases the lines of code is less than duplicated lines.

Where is the issue ? How do I address it ?

Screenshot of the error from sonar demo


Solution

  • What you're seeing is the difference between Lines and Lines of Code. For instance, how many of each are below:

    public void foo() {
    
      int i = 0;
    
      for (int j=0; j < 10; j++) 
    
        doTheThing(j);
    
     }
    

    I'd say that's 4 LoC (maybe 5. Don't remember if the '}' counts) but 9 Lines.