Skip to content

Commit

Permalink
Don't crash on b ? null : null;
Browse files Browse the repository at this point in the history
  • Loading branch information
smillst authored Aug 8, 2024
1 parent aeb1eb2 commit 9cb1cf4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions framework/tests/all-systems/Issue6743.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Issue6743 {
void foo(boolean b) {
Object o = b ? null : null;
}
}

0 comments on commit 9cb1cf4

Please sign in to comment.