diff --git a/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java b/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java index fca310c9f390..7effd14ca844 100644 --- a/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java +++ b/java/java-impl/src/com/intellij/codeInspection/dataFlow/StandardInstructionVisitor.java @@ -147,6 +147,10 @@ public class StandardInstructionVisitor extends InstructionVisitor { } } + if (instruction.getCastTo() instanceof PsiPrimitiveType) { + memState.push(runner.getFactory().getBoxedFactory().createUnboxed(memState.pop())); + } + return nextInstruction(instruction, runner, memState); } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/Boxing128.java b/java/java-tests/testData/inspection/dataFlow/fixture/Boxing128.java new file mode 100644 index 000000000000..1bdd5a48ac13 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/Boxing128.java @@ -0,0 +1,11 @@ +class Foo { + public void foo() { + Integer a = 128; + Integer b = (int) a;// cast is necessary because new object is created + Integer c = 128; + + System.out.println(a == b); + System.out.println(a == c); + } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java index 768679bdb501..8202b8371805 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionFixtureTest.java @@ -64,4 +64,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas public void testComparingToNotNullShouldNotAffectNullity() throws Throwable { doTest(); } public void testStringTernaryAlwaysTrue() throws Throwable { doTest(); } + public void testBoxing128() throws Throwable { doTest(); } + }