diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/types/DfGenericObjectType.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/types/DfGenericObjectType.java index 534347174e8e..65e1e3e64ace 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/types/DfGenericObjectType.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/types/DfGenericObjectType.java @@ -249,9 +249,11 @@ class DfGenericObjectType extends DfAntiConstantType 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; + } } } } diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/EphemeralInIfChain.java b/java/java-tests/testData/inspection/dataFlow/fixture/EphemeralInIfChain.java index 38e606f9dcb8..a483a4808142 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/EphemeralInIfChain.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/EphemeralInIfChain.java @@ -14,10 +14,24 @@ class Test { else if (x == MyEnum.C) { s = "C"; } - System.out.println(s.trim()); + System.out.println(s.trim()); // 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";