[Bug] Conditionally executed blocks should be reachable

170 views
Skip to first unread message

johannes...@gmail.com

unread,
Jan 3, 2018, 5:01:54 AM1/3/18
to SonarQube
Hello! I am using SonarQube 6.5.0.27846 with SonarJava 4.15.0.12310.

I have the following method:

private static double selectPivot(double[][] matrix) {
       
double maxLineQuotient = 0.0;
       
int size = matrix.length;
        swapIndex
= 0;
       
       
for (int i = 0; i < size; i++) {
           
// calculate row sum
           
double lineQuotient = 0.0;
           
for (int j = 0; j < size; j++) {
                lineQuotient
+= Math.abs(matrix[i][j]);
           
}
           
           
// skip row if sum is zero
           
if (lineQuotient == 0.0) {
               
continue;
           
}
           
           
// calculate the line quotient a[i][0]/sum
            lineQuotient
= Math.abs(matrix[i][0]) / lineQuotient;
           
           
// search the greatest line quotient
           
if (lineQuotient > maxLineQuotient) {
                maxLineQuotient
= lineQuotient;
                swapIndex
= i;
           
}
       
}
       
       
if (swapIndex > 0) {
           
// swap line 0 with pivot line
            swapLines
(matrix, 0, swapIndex);
       
}
       
       
// return pivot element
       
return matrix[0][0];
   
}

Now SonarQube reports a bug regarding the line
if (swapIndex > 0) "Change this condition so that it does not always evaluate to "false""

I think this a bug in the scanner. i is changed in the for loop. So I think my code is correct. After the for loop variable swapIndex can be =0 or >0.

I updated SonarJava today. The bug did not exist in the version I had before.

Nicolas Peru

unread,
Mar 29, 2018, 11:20:06 AM3/29/18
to johannes...@gmail.com, SonarQube
Hey, 

Sorry for the delay answering you : your case is a bit tricky but it is a variation of this problem of nested loops limit : https://jira.sonarsource.com/browse/SONARJAVA-1940 
No plan on our side in the shorterm to announce you but this issue should be fix someday. In the meantime you can mark the issue as falsepositive and follow this ticket.
Cheers, 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/483ceb80-b018-4de9-9f11-90f5be5d3184%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource
Reply all
Reply to author
Forward
0 new messages