versions used:
- Version 7.9.1 (build 27448) Community Edition
- SonarJava: 5.14 (build 18788)
In my opinion the rule “squid:S1067: Expressions should not be too complex” creates a false-positive in case of just multiple instanceof checks (I know this is not good OO design). The code is not getting significantly more complex if you add another instanceof check.
(Perhaps there are other scenarios of the same type.)
private static boolean isRelevant(Object artifact) {
return artifact instanceof A
|| artifact instanceof B
|| artifact instanceof C
|| artifact instanceof D
|| artifact instanceof E
|| artifact instanceof F
|| artifact instanceof G
|| artifact instanceof H
|| artifact instanceof I;
This rule does not care about number of instanceof but about number of conditional operators. Obviously there are pretty a lot of them. If you believe this code does not reduce the quality of the project just won't fix the issue, but that’s not a FP in terms of rule definition.
We actually have a false positive case to demonstrate. In this constructor all of logical OR’s are counted, but the count does not restart for each statement, instead counting within the scope of the method, despite the individual statement scopes.
Is this actually a bug, or something we can configure?