spotbugs / spotbugs

SpotBugs is FindBugs' successor. A tool for static analysis to look for bugs in Java code.
https://spotbugs.github.io/
GNU Lesser General Public License v2.1
3.51k stars 592 forks source link

False Positive: IL_INFINITE_LOOP #2936

Open raghucssit opened 7 months ago

raghucssit commented 7 months ago
public class TestClass {

    public void sampleMethod() throws Exception {

        // some random last index.
        int lastIndex_o1_n1 = 5;
        // start index is always higher than start index.
        int startIndex_o1 = lastIndex_o1_n1 + 1;
        // Loop can't be entered because start is higher.
        for (int i = startIndex_o1; i <= lastIndex_o1_n1; i++) {
            System.out.println("Loop can't be entered. So can never go infinite.");
        }
    }

    public static void main(String[] args) throws Exception {
        new TestClass().sampleMethod();
    }
}

image

welcome[bot] commented 7 months ago

Thanks for opening your first issue here! :smiley: Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

raghucssit commented 7 months ago

This looks like an opposite case of Infinite loop. i.e. Loop can never be entered making statements inside for loop useless.

iloveeclipse commented 7 months ago

Loop can't be entered. So can never go infinite.

:+1:

iloveeclipse commented 7 months ago

I wonder if this is just wrong bug / message reported?

raghucssit commented 7 months ago

I think so. This is more of dead code scenario.

JuditKnoll commented 7 months ago

I think https://github.com/spotbugs/spotbugs/pull/2073 could help solve this issue.