spotbugs
spotbugs copied to clipboard
IL_INFINITE_LOOP not detected in infinite loop
The following code runs indefinitely as there is no stop condition in the loop. However, SpotBugs is not able to detect this. I can confirm that it also does not detect similar for loop (e.g., for (;true;)).
class InfiniteLoopExample {
public void showBug() {
int counter = 0;
while (true) { // BUG: IL: An apparent infinite loop (IL_INFINITE_LOOP)
System.out.println("Counter: " + counter);
counter++;
}
}
public static void main(String[] args) {
InfiniteLoopExample example = new InfiniteLoopExample();
example.showBug();
}
}
This is similar to issue-1866. However, it is not the same as here the variable inside the loop is local and the infinite loop is still not detected, unlike issue-1866.
SpotBugs version: 4.9.2
Java: Temurin openjdk 21.0.7
Ran from CLI as the following two commands:
export SPOTBUGS_JAR=/path/to/spotbugs.jar
javac InfiniteLoopExample.java && \
java -jar $SPOTBUGS_JAR \
-low \
-effort:max \
InfiniteLoopExample.class