[java-dfa] Do not allow null in ephemeral value

GitOrigin-RevId: cca32e434c96998346fc6759f3d699bc6ada799a
This commit is contained in:
Tagir Valeev
2020-10-08 03:09:44 +00:00
committed by intellij-monorepo-bot
parent cf5e59d8f3
commit f65c12ccbd
2 changed files with 21 additions and 5 deletions
@@ -249,9 +249,11 @@ class DfGenericObjectType extends DfAntiConstantType<Object> implements DfRefere
} else if (!myNotValues.containsAll(otherNotValues)) {
notValues = new THashSet<>(myNotValues);
notValues.addAll(otherNotValues);
DfEphemeralReferenceType ephemeralValue = checkEphemeral(constraint, notValues);
if (ephemeralValue != null) {
return ephemeralValue;
if (nullability == DfaNullability.NOT_NULL) {
DfEphemeralReferenceType ephemeralValue = checkEphemeral(constraint, notValues);
if (ephemeralValue != null) {
return ephemeralValue;
}
}
}
}
@@ -14,10 +14,24 @@ class Test {
else if (x == MyEnum.C) {
s = "C";
}
System.out.println(s.trim());
System.out.println(s.<warning descr="Method invocation 'trim' may produce 'NullPointerException'">trim</warning>()); // reachable if x is null
}
void test2(MyEnum x) {
void test1(@NotNull MyEnum x) {
String s = null;
if (x == MyEnum.A) {
s = "A";
}
else if (x == MyEnum.B) {
s = "B";
}
else if (x == MyEnum.C) {
s = "C";
}
System.out.println(s.trim()); // ephemerably reachable
}
void test2(@NotNull MyEnum x) {
String s = null;
if (x == MyEnum.A) {
s = "A";