I am using SonarLint 4.2 with Eclipse.
Here is a sample snippet, where squid:S2589
detected unreasonably:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class feladat {
private static final long MAX_NORMAL = 800;
public static void main(String[] args) {
int count;
List<Flooding> floodings = new ArrayList<>();
Flooding bestFlooding = null;
long bestTail = -1;
Scanner scanner = new Scanner(System.in);
count = scanner.nextInt();
Flooding currentFlooding = null;
for (int n = 1; n <= count; n++) {
long value = scanner.nextLong();
boolean isFlooding = value > MAX_NORMAL;
if (isFlooding) {
if (currentFlooding == null) {
currentFlooding = new Flooding(n, value);
floodings.add(currentFlooding);
} else {
currentFlooding.add(n, value);
}
} else if (currentFlooding != null) {
long tail = currentFlooding.getTail();
if (bestFlooding == null || tail < bestTail) { // NOSONAR is not gratuitous!
bestFlooding = currentFlooding;
bestTail = tail;
}
currentFlooding = null;
}
}
scanner.close();
// etc.
}
private static class Flooding {
final int startLocation;
int maxLocation = -1;
long maxValue = -1;
int endLocation = -1;
Flooding(int startLocation, long startValue) {
this.startLocation = startLocation;
this.maxLocation = startLocation;
this.maxValue = startValue;
this.endLocation = startLocation;
}
void add(int location, long value) {
this.endLocation = location;
if (value > this.maxValue) {
this.maxLocation = location;
this.maxValue = value;
}
}
int getTail() {
return endLocation - maxLocation;
}
}
}
NOSONAR should not be necessary.