mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-188135 Report when always true/false expression in and/or chain causes short-circuit
This commit is contained in:
+8
-2
@@ -780,8 +780,14 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
|
||||
// Note that in `assert unknownExpression && trueExpression;` the trueExpression should not be reported
|
||||
// because this assert is essentially the shortened `assert unknownExpression; assert trueExpression;`
|
||||
// which is not reported.
|
||||
anchor = parent;
|
||||
continue;
|
||||
boolean causesShortCircuit = (tokenType.equals(JavaTokenType.OROR) == evaluatesToTrue) &&
|
||||
ArrayUtil.getLastElement(((PsiPolyadicExpression)parent).getOperands()) != anchor;
|
||||
if (!causesShortCircuit) {
|
||||
// We still report `assert trueExpression || unknownExpression`, because here `unknownExpression` is never checked
|
||||
// which is probably not intended.
|
||||
anchor = parent;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -23,7 +23,10 @@ class Test {
|
||||
|
||||
private static void testOr(boolean a, boolean b, boolean c) {
|
||||
if(b) {
|
||||
assert a || b || c;
|
||||
// c is never checked: probably not intended; report
|
||||
assert a || <warning descr="Condition 'b' is always 'true'">b</warning> || c;
|
||||
|
||||
assert a || c || b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user