IDEA-178198 Expressions using constants are not reported as always false

This commit is contained in:
peter
2017-08-31 17:39:08 +02:00
parent 0b752f7819
commit ab4837ff9f
2 changed files with 17 additions and 2 deletions
@@ -835,8 +835,8 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
private static boolean isConstantOfType(PsiElement element, PsiPrimitiveType... types) {
PsiElement resolved = element instanceof PsiReferenceExpression ? ((PsiReferenceExpression)element).resolve() : null;
if (!(resolved instanceof PsiField)) return false;
PsiField field = (PsiField)resolved;
return field.hasModifierProperty(PsiModifier.FINAL) && field.hasModifierProperty(PsiModifier.STATIC) &&
PsiVariable field = (PsiVariable)resolved;
return field.hasModifierProperty(PsiModifier.STATIC) && PsiUtil.isCompileTimeConstant(field) &&
ArrayUtil.contains(field.getType(), types);
}
@@ -51,4 +51,19 @@ public class SuppressStaticFlags {
System.out.println("Literals");
}
}
public static final boolean nonCompileTimeConstant = new java.util.Random().nextBoolean();
public void hello1(Object file) {
if (file == null) {
return;
}
if (<warning descr="Condition 'file == null && nonCompileTimeConstant' is always 'false'"><warning descr="Condition 'file == null' is always 'false'">file == null</warning> && nonCompileTimeConstant</warning>) {
return;
}
System.out.println("hello");
}
}