dfa: just don't assume initialized final fields are notnull, it doesn't help, but hurts and slows things down (IDEA-124323)

This commit is contained in:
peter
2014-04-24 17:56:38 +02:00
parent b6be84f984
commit 78dafa03c5
3 changed files with 14 additions and 19 deletions
@@ -115,19 +115,6 @@ public class DfaValueFactory {
return getConstFactory().create(literal);
}
private static boolean isNotNullExpression(PsiExpression initializer, PsiType type) {
if (initializer instanceof PsiNewExpression) {
return true;
}
if (initializer instanceof PsiPolyadicExpression) {
if (type != null && type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
return true;
}
}
return false;
}
@Nullable
public DfaValue createReferenceValue(PsiReferenceExpression referenceExpression) {
PsiElement psiSource = referenceExpression.resolve();
@@ -139,12 +126,6 @@ public class DfaValueFactory {
if (variable.hasModifierProperty(PsiModifier.FINAL) && !variable.hasModifierProperty(PsiModifier.TRANSIENT)) {
DfaValue constValue = getConstFactory().create(variable);
if (constValue != null) return constValue;
PsiExpression initializer = variable.getInitializer();
PsiType type = initializer == null ? null : initializer.getType();
if (initializer != null && type != null && isNotNullExpression(initializer, type)) {
return createTypeValue(type, Nullness.NOT_NULL);
}
}
if (!variable.hasModifierProperty(PsiModifier.VOLATILE) && isEffectivelyUnqualified(referenceExpression)) {
@@ -0,0 +1,13 @@
class Test {
public static final Test INSTANCE = new Test();
public Test() {
if (INSTANCE == null) {
System.out.println("Instance is null");
}
}
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
@@ -192,6 +192,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testLastConstantConditionInAnd() { doTest(); }
public void testTransientFinalField() { doTest(); }
public void testFinalFieldDuringInitialization() { doTest(); }
public void _testSymmetricUncheckedCast() { doTest(); } // http://youtrack.jetbrains.com/issue/IDEABKL-6871
public void testNullCheckDoesntAffectUncheckedCast() { doTest(); }
public void testThrowNull() { doTest(); }