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 95500ee2aff..bd03929758f 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 @@ -2722,7 +2722,15 @@ public Node visitClass(ClassTree tree, Void p) { 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. + Tree parent = TreePathUtil.getContextForPolyExpression(getCurrentPath()); + if (parent != null) { + exprType = TreeUtils.typeOf(parent); + } else { + exprType = TypesUtils.getObjectTypeMirror(env); + } + } Label trueStart = new Label(); Label falseStart = new Label(); Label merge = new Label(); diff --git a/framework/tests/all-systems/Issue6743.java b/framework/tests/all-systems/Issue6743.java new file mode 100644 index 00000000000..2f3165545be --- /dev/null +++ b/framework/tests/all-systems/Issue6743.java @@ -0,0 +1,5 @@ +public class Issue6743 { + void foo(boolean b) { + Object o = b ? null : null; + } +}