From 012d1147d49a6ba0f491f88a03ab56195b657197 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 5 Aug 2013 16:35:24 +0200 Subject: [PATCH] dfa inspection CCE analyzer should check erasures only --- .../dataFlow/value/DfaTypeValue.java | 17 +++++++---------- .../dataFlow/fixture/NoGenericCCE.java | 8 ++++++++ .../codeInspection/DataFlowInspectionTest.java | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/NoGenericCCE.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java index 9d954b587f65..e7f5a9c35294 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java @@ -25,8 +25,10 @@ package com.intellij.codeInspection.dataFlow.value; import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiKeyword; import com.intellij.psi.PsiType; +import com.intellij.psi.util.TypeConversionUtil; import com.intellij.util.containers.HashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -47,12 +49,10 @@ public class DfaTypeValue extends DfaValue { @NotNull public DfaTypeValue create(@NotNull PsiType type, boolean nullable) { + type = TypeConversionUtil.erasure(type); mySharedInstance.myType = type; - mySharedInstance.myCanonicalText = type.getCanonicalText(); + mySharedInstance.myCanonicalText = StringUtil.notNullize(type.getCanonicalText(), PsiKeyword.NULL); mySharedInstance.myIsNullable = nullable; - if (mySharedInstance.myCanonicalText == null) { - mySharedInstance.myCanonicalText = PsiKeyword.NULL; - } String id = mySharedInstance.toString(); ArrayList conditions = myStringToObject.get(id); @@ -65,7 +65,7 @@ public class DfaTypeValue extends DfaValue { } } - DfaTypeValue result = new DfaTypeValue(type, nullable, myFactory); + DfaTypeValue result = new DfaTypeValue(type, nullable, myFactory, mySharedInstance.myCanonicalText); conditions.add(result); return result; } @@ -83,14 +83,11 @@ public class DfaTypeValue extends DfaValue { super(factory); } - private DfaTypeValue(PsiType type, boolean isNullable, DfaValueFactory factory) { + private DfaTypeValue(PsiType type, boolean isNullable, DfaValueFactory factory, String canonicalText) { super(factory); myType = type; myIsNullable = isNullable; - myCanonicalText = type.getCanonicalText(); - if (myCanonicalText == null) { - myCanonicalText = PsiKeyword.NULL; - } + myCanonicalText = canonicalText; } public PsiType getType() { diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/NoGenericCCE.java b/java/java-tests/testData/inspection/dataFlow/fixture/NoGenericCCE.java new file mode 100644 index 000000000000..edb3bdc3ada6 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/NoGenericCCE.java @@ -0,0 +1,8 @@ +import java.util.ArrayList; + +class X { + public static void main(String[] args) { + Object list = new ArrayList<>(); + ArrayList list1 = (ArrayList) list; + } +} \ 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 6de4bef6febd..6f9c7b089386 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -285,4 +285,5 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testContractAnnotation() { doTest(); } public void testBoxingImpliesNotNull() { doTest(); } public void testLargeIntegersAreNotEqualWhenBoxed() { doTest(); } + public void testNoGenericCCE() { doTest(); } }