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.