diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaConstValue.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaConstValue.java index 5c8d7ca276d5..49028dd66e7b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaConstValue.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaConstValue.java @@ -70,6 +70,10 @@ public class DfaConstValue extends DfaValue { DfaConstValue unboxed = createFromValue(boo, PsiType.BOOLEAN, variable); return myFactory.getBoxedFactory().createBoxed(unboxed); } + PsiExpression initializer = variable.getInitializer(); + if (initializer instanceof PsiLiteralExpression && initializer.textMatches(PsiKeyword.NULL)) { + return dfaNull; + } return null; } return createFromValue(value, type, variable); diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ReturningNullConstant.java b/java/java-tests/testData/inspection/dataFlow/fixture/ReturningNullConstant.java new file mode 100644 index 000000000000..4f9cfddc9f54 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ReturningNullConstant.java @@ -0,0 +1,11 @@ +import org.jetbrains.annotations.NotNull; + +class BrokenAlignment { + + private static final String DEFAULT = null; + + @NotNull + public String getDefaultValue() { + return DEFAULT; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index 0acf071bbf4a..490ded30353c 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -111,6 +111,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testSynchronizingOnNullable() throws Throwable { doTest(); } public void testSwitchOnNullable() { doTest(); } public void testReturningNullFromVoidMethod() throws Throwable { doTest(); } + public void testReturningNullConstant() { doTest(); } public void testCatchRuntimeException() throws Throwable { doTest(); } // IDEA-129331