DFA: do not report explicit Boolean.TRUE/Boolean.FALSE as always true/false

GitOrigin-RevId: ad6eeba399d80a343ca87fd2fc11539a22331c9e
This commit is contained in:
Tagir Valeev
2019-12-16 11:59:04 +07:00
committed by intellij-monorepo-bot
parent 01080b23c5
commit a6e017ef0e
4 changed files with 56 additions and 44 deletions

View File

@@ -802,6 +802,16 @@ public abstract class DataFlowInspectionBase extends AbstractBaseJavaLocalInspec
// For conditional the root cause (constant condition or both branches constant) should be already reported for branches
if (anchor instanceof PsiConditionalExpression) return true;
PsiExpression expression = (PsiExpression)anchor;
if (expression instanceof PsiReferenceExpression) {
PsiReferenceExpression ref = (PsiReferenceExpression)expression;
if ("TRUE".equals(ref.getReferenceName()) || "FALSE".equals(ref.getReferenceName())) {
PsiElement target = ref.resolve();
if (target instanceof PsiField) {
PsiClass containingClass = ((PsiField)target).getContainingClass();
if (containingClass != null && CommonClassNames.JAVA_LANG_BOOLEAN.equals(containingClass.getQualifiedName())) return true;
}
}
}
PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent());
// Don't report "x" in "x == null" as will be anyways reported as "always true"
if (parent instanceof PsiBinaryExpression && ExpressionUtils.getValueComparedWithNull((PsiBinaryExpression)parent) != null) return true;