diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaBoxedValue.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaBoxedValue.java index f16206dad194..eddb2bc9a2e5 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaBoxedValue.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaBoxedValue.java @@ -15,12 +15,13 @@ */ package com.intellij.codeInspection.dataFlow.value; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.containers.ContainerUtil; -import java.util.HashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.HashMap; import java.util.Map; public class DfaBoxedValue extends DfaValue { @@ -70,8 +71,7 @@ public class DfaBoxedValue extends DfaValue { return ((DfaBoxedValue)value).getWrappedValue(); } if (value instanceof DfaConstValue) { - if (value == value.myFactory.getConstFactory().getNull()) return DfaUnknownValue.getInstance(); - return value; + return TypeConversionUtil.isPrimitiveAndNotNull(((DfaConstValue)value).getType()) ? value : DfaUnknownValue.getInstance(); } if (value instanceof DfaVariableValue) { DfaVariableValue var = (DfaVariableValue)value; diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/BoxingIncorrectLiteral.java b/java/java-tests/testData/inspection/dataFlow/fixture/BoxingIncorrectLiteral.java new file mode 100644 index 000000000000..ea5e466447b7 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/BoxingIncorrectLiteral.java @@ -0,0 +1,5 @@ +class Testcase { + void test() { + Character x = "foo"; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java index 9ad5ce7e06b6..83ad212215c1 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/DataFlowInspectionTest.java @@ -640,4 +640,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase { public void testStringEquality() { doTest(); } public void testAssignmentFieldAliasing() { doTest(); } public void testNewBoxedNumberEquality() { doTest(); } + public void testBoxingIncorrectLiteral() { doTest(); } }