From 5cc38ebdd6060ea7fcf32fc1acbd302ea2fe686a Mon Sep 17 00:00:00 2001 From: Suzanne Millstein Date: Thu, 8 Aug 2024 10:28:13 -0700 Subject: [PATCH] Handle b ? null : null;. --- .../dataflow/cfg/builder/CFGTranslationPhaseOne.java | 10 +++++++++- framework/tests/all-systems/Issue6743.java | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 framework/tests/all-systems/Issue6743.java 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; + } +}