mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-64875 "Constant conditions and exceptions" should eliminate false positives by analyzing static final constants
This commit is contained in:
@@ -74,10 +74,13 @@ public class DfaValueFactory {
|
||||
DfaValue constValue = getConstFactory().create(variable);
|
||||
if (constValue != null) return constValue;
|
||||
|
||||
if (!(psiSource instanceof PsiField)) {
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer instanceof PsiPolyadicExpression && variable.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
PsiType type = initializer.getType();
|
||||
PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer != null && variable.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
PsiType type = initializer.getType();
|
||||
if (initializer instanceof PsiNewExpression) {
|
||||
return getNotNullFactory().create(type);
|
||||
}
|
||||
if (initializer instanceof PsiPolyadicExpression) {
|
||||
if (type != null && type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
|
||||
return getNotNullFactory().create(type);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
class Class1 {
|
||||
public void f(@Nullable Object o) {
|
||||
o = o != null ? o : Class2.O;
|
||||
o.toString();
|
||||
}
|
||||
}
|
||||
class Class2 {
|
||||
static final Object O = new Object();
|
||||
}
|
||||
@@ -74,5 +74,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
|
||||
public void testVisitFinallyOnce() throws Throwable { doTest(); }
|
||||
public void testNotEqualsDoesntImplyNotNullity() throws Throwable { doTest(); }
|
||||
public void testEqualsEnumConstant() throws Throwable { doTest(); }
|
||||
public void testEqualsConstant() throws Throwable { doTest(); }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user