DataFlowInspectionBase: do not report always-null for variables of java.lang.Void type

This commit is contained in:
Tagir Valeev
2018-08-08 17:41:04 +07:00
parent 2111907b7e
commit 22cbe8cb0b
2 changed files with 7 additions and 0 deletions
@@ -751,6 +751,9 @@ public class DataFlowInspectionBase extends AbstractBaseJavaLocalInspectionTool
if (parent instanceof PsiBinaryExpression && ExpressionUtils.getValueComparedWithNull((PsiBinaryExpression)parent) != null) return true;
// Dereference of null will be covered by other warning
if (ExpressionUtils.isVoidContext(expression) || isDereferenceContext(expression)) return true;
// We assume all Void variables as null because you cannot instantiate it without dirty hacks
// However reporting them as "always null" looks redundant (dereferences or comparisons will be reported though).
if (TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_VOID, expression.getType())) return true;
if (isFlagCheck(anchor)) return true;
boolean condition = isCondition(expression);
if (!condition && expression instanceof PsiReferenceExpression) {
@@ -29,4 +29,8 @@ class Test {
native Object process(@Nullable Object obj);
native void doSmth(@Nullable Object obj);
void bar(Void p) {
System.out.println(p);
}
}