From 22cbe8cb0b3c50c4bbdbb5308bd65fe49916736f Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Wed, 8 Aug 2018 17:31:20 +0700 Subject: [PATCH] DataFlowInspectionBase: do not report always-null for variables of java.lang.Void type --- .../codeInspection/dataFlow/DataFlowInspectionBase.java | 3 +++ .../inspection/dataFlow/fixture/ReportAlwaysNull.java | 4 ++++ 2 files changed, 7 insertions(+) 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 fcb645e6df99..337498fbb7af 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 @@ -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) { diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ReportAlwaysNull.java b/java/java-tests/testData/inspection/dataFlow/fixture/ReportAlwaysNull.java index a7ee00a8ffd6..bdf6e9838373 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/ReportAlwaysNull.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ReportAlwaysNull.java @@ -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); + } } \ No newline at end of file