S2189 potential infinite loop not detected

Hi we currently used SonarQube 7.5 and we face a potential infinite loop not detected by sonar

In the snippet below, if the send null to the increase function in the “condition” param the script will be in infinite loop,

but the rule S2189 - [Do not use an empty infinite loop], didn’t see any problem here

can sonar be able to detect this ?

Thanks a lot Alex.

exemple snippet :

    public class InfiniteLoop {

public static void main(String[] args) {
	int start = 1;
	int limit = 100;
	String condition = null;
	increase(limit, condition, start);
}

static int increase(int limit, String condition, int start) {
	while (start < limit) {
		System.out.println("im in the loop");
		if (null != condition) {
			//do something wonderful with your condition
			start ++;
		}else{
			System.out.println("here we are in infinite loop");
		}
	}
	return start;
}
}

Hi,

Thanks for pointing out this case.
Let’s be clear : this is a difficult one. This requires a quite advanced level of analysis, which would involve some satisfiability techniques, integer dataflow analysis and other fun stuff like this.
We do have in mind (and are currently working) on some advanced analysis techniques that could lead us to improve this rule to detect such cases but it is too early to come up with a commitment or timeframe.

In short, the current rule is not able to detect such cases and it is HARD to do.

Hello,
We are using python and found this code snippet that caused an infinite loop during testing time.

     i = 0
    while i < 100:
         //production code
        else:
            i += 1

Unfortunately, this problem was not detected and since it passed, we moved it further from dev system, which got us into trouble with the QA team :slight_smile:
Is this something that has been taken care of? please help. thanks