diff --git a/dataflow/src/main/java/org/checkerframework/dataflow/cfg/builder/CFGTranslationPhaseOne.java b/dataflow/src/main/java/org/checkerframework/dataflow/cfg/builder/CFGTranslationPhaseOne.java index bd03929758f..ad8d5b47730 100644 --- a/dataflow/src/main/java/org/checkerframework/dataflow/cfg/builder/CFGTranslationPhaseOne.java +++ b/dataflow/src/main/java/org/checkerframework/dataflow/cfg/builder/CFGTranslationPhaseOne.java @@ -2723,11 +2723,13 @@ public Node visitConditionalExpression(ConditionalExpressionTree tree, Void p) { // see JLS 15.25 TypeMirror exprType = TreeUtils.typeOf(tree); if (exprType.getKind() == TypeKind.NULL) { - // Happens when the 2nd and 3rd operands are both null, i.e. b ? null : null. + // Happens when the 2nd and 3rd operands are both null, e.g.: b ? null : null Tree parent = TreePathUtil.getContextForPolyExpression(getCurrentPath()); if (parent != null) { exprType = TreeUtils.typeOf(parent); - } else { + // exprType is null when the condition is non-atomic, e.g.: x.isEmpty() ? null : null + } + if (parent == null || exprType == null) { exprType = TypesUtils.getObjectTypeMirror(env); } } diff --git a/framework/tests/all-systems/Issue6785.java b/framework/tests/all-systems/Issue6785.java new file mode 100644 index 00000000000..52f0f08ec1d --- /dev/null +++ b/framework/tests/all-systems/Issue6785.java @@ -0,0 +1,7 @@ +import org.checkerframework.checker.nullness.qual.Nullable; + +public class Issue6785 { + @Nullable String foo2(String x) { + return x.isEmpty() ? null : null; + } +}