I get sonar bug with code java:S2189 "Loops should not be infinite". I have explicit condition to finish my loop. Maybe I'm not seeing the problem. Is there a proper explanation for this bug?
It may be related with SonarQube's scanner version. The version difference also changes the situation.
This code has bug for SonarQube Scanner 4.2.0.1873
This code has no bug for SonarQube Scanner 3.0.3.778
public class SonarBug implements Runnable {
private final LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
@Override
public void run() {
boolean continueCondition = true;
while (continueCondition) {
Integer takenInteger;
try {
takenInteger = queue.take();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
continueCondition = false;
continue;
}
callSomeFunction(takenInteger);
}
System.out.println("Finished.");
}
private void callSomeFunction(Integer takenInteger) {
}
}