diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java index fd910ba7ea8e..efd4135af3ad 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java @@ -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; diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/SkipAssertions.java b/java/java-tests/testData/inspection/dataFlow/fixture/SkipAssertions.java index 4ae6546f4a59..72994b72f10c 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/SkipAssertions.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/SkipAssertions.java @@ -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 || b || c; + + assert a || c || b; } }