Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash on b ? null : null;. #6752

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}