FP suspected in "Conditionally executed blocks should be reachable" (squid:S2583) and "Boolean expressions should not be gratuitous" (squid:S2589)

138 views
Skip to first unread message

didier.d...@gmail.com

unread,
Jan 18, 2018, 9:21:03 AM1/18/18
to SonarQube
Hi,

I'm using Sonar java plugin v4.15.0.12310, and this code below triggers several warnings:

     public static void main(final String[] args) {
        boolean c1 = false;
        boolean c2 = false;
        boolean c3 = false;
        boolean c4 = false;
        for (int i = 0; i < 10; i++) {
            if (!c1 && i < 10) {
                c1 = true;
            } else if (c1 && !c2) {
                c2 = true;
            } else if (c1 && c2 && !c3) { // says C2 always true and !c3 always true
                c3 = true;
            } else if (c1 && c2 && c3) { // says c1 is always false
                c4 = true;
                System.out.println(i);
                break;
            }
        }
        if (c1 && c2 && c3 && c4) { // says c3 is always false
            System.out.println("All is true");
        }

This code indeed displays the message "All is true", proving that the warnings are false.

Is this a known bug?

Thanks,

Didier

didier.d...@gmail.com

unread,
Jan 24, 2018, 4:43:48 AM1/24/18
to SonarQube
Hi,

maybe it is related to SONARJAVA-2606 and SONARJAVA-2523?

Didier

Michael Gumowski

unread,
Jan 30, 2018, 4:44:51 AM1/30/18
to didier.d...@gmail.com, SonarQube
Hello Didier,

Thanks a lot for your feedback. It is indeed highly related to the ticket SONARJAVA-2523, and due to the way the Symbolic Execution engine from the SonarJava analyzer is currently handling loops. This is a know limitation of the engine, which we plan to rework at some point. I linked your thread to the ticket. Nothing you can do for the time being, apart marking these issues as False Positives.

Regards,
Michael

--
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/6796cbe2-6911-42b4-b071-d428fd13ba3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Michael Gumowski | SonarSource
Software Developer, Language Team
https://www.sonarsource.com
Reply all
Reply to author
Forward
0 new messages