mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-178198 Expressions using constants are not reported as always false
This commit is contained in:
+2
-2
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user