From 36fa0a22f9948cda50ccf0f50b3c1e277fc4c1e5 Mon Sep 17 00:00:00 2001 From: Anders Schack-Mulligen Date: Wed, 4 Feb 2026 13:38:11 +0100 Subject: [PATCH] Java: Rename getTrueExpr/getFalseExpr on ConditionalExpr to getThen/getElse. --- .../examples/snippets/ternaryconditional.ql | 6 ++-- java/ql/lib/semmle/code/java/Expr.qll | 32 ++++++++++++++----- .../lib/semmle/code/java/PrettyPrintAst.qll | 4 +-- .../semmle/code/java/controlflow/Guards.qll | 8 +---- .../semmle/code/java/dataflow/NullGuards.qll | 4 +-- .../Likely Bugs/Arithmetic/CondExprTypes.ql | 4 +-- .../Comparison/StringComparison.ql | 4 +-- .../Comparison/UselessComparisonTest.ql | 4 +-- .../Boolean Logic/SimplifyBoolExpr.ql | 16 +++++----- .../Implementation Hiding/StaticArray.ql | 4 +-- .../legacy/AutoBoxing.ql | 4 +-- 11 files changed, 49 insertions(+), 41 deletions(-) diff --git a/java/ql/examples/snippets/ternaryconditional.ql b/java/ql/examples/snippets/ternaryconditional.ql index bbd82770a16..867ea024674 100644 --- a/java/ql/examples/snippets/ternaryconditional.ql +++ b/java/ql/examples/snippets/ternaryconditional.ql @@ -11,7 +11,7 @@ import java from ConditionalExpr e where - e.getTrueExpr().getType() != e.getFalseExpr().getType() and - not e.getTrueExpr().getType() instanceof NullType and - not e.getFalseExpr().getType() instanceof NullType + e.getThen().getType() != e.getElse().getType() and + not e.getThen().getType() instanceof NullType and + not e.getElse().getType() instanceof NullType select e diff --git a/java/ql/lib/semmle/code/java/Expr.qll b/java/ql/lib/semmle/code/java/Expr.qll index 9e958b36471..757bef86e3d 100644 --- a/java/ql/lib/semmle/code/java/Expr.qll +++ b/java/ql/lib/semmle/code/java/Expr.qll @@ -166,8 +166,8 @@ class CompileTimeConstantExpr extends Expr { // The ternary conditional operator ` ? : `. exists(ConditionalExpr e | this = e | e.getCondition().isCompileTimeConstant() and - e.getTrueExpr().isCompileTimeConstant() and - e.getFalseExpr().isCompileTimeConstant() + e.getThen().isCompileTimeConstant() and + e.getElse().isCompileTimeConstant() ) or // Access to a final variable initialized by a compile-time constant. @@ -1464,26 +1464,42 @@ class ConditionalExpr extends Expr, @conditionalexpr { Expr getCondition() { result.isNthChildOf(this, 0) } /** + * DEPRECATED: Use getThen() instead. + * * Gets the expression that is evaluated if the condition of this * conditional expression evaluates to `true`. */ - Expr getTrueExpr() { result.isNthChildOf(this, 1) } + deprecated Expr getTrueExpr() { result.isNthChildOf(this, 1) } + + /** + * DEPRECATED: Use getElse() instead. + * + * Gets the expression that is evaluated if the condition of this + * conditional expression evaluates to `false`. + */ + deprecated Expr getFalseExpr() { result.isNthChildOf(this, 2) } + + /** + * Gets the expression that is evaluated if the condition of this + * conditional expression evaluates to `true`. + */ + Expr getThen() { result.isNthChildOf(this, 1) } /** * Gets the expression that is evaluated if the condition of this * conditional expression evaluates to `false`. */ - Expr getFalseExpr() { result.isNthChildOf(this, 2) } + Expr getElse() { result.isNthChildOf(this, 2) } /** * Gets the expression that is evaluated by the specific branch of this - * conditional expression. If `true` that is `getTrueExpr()`, if `false` - * it is `getFalseExpr()`. + * conditional expression. If `true` that is `getThen()`, if `false` + * it is `getElse()`. */ Expr getBranchExpr(boolean branch) { - branch = true and result = this.getTrueExpr() + branch = true and result = this.getThen() or - branch = false and result = this.getFalseExpr() + branch = false and result = this.getElse() } /** diff --git a/java/ql/lib/semmle/code/java/PrettyPrintAst.qll b/java/ql/lib/semmle/code/java/PrettyPrintAst.qll index 4538b817266..64e44b2cec4 100644 --- a/java/ql/lib/semmle/code/java/PrettyPrintAst.qll +++ b/java/ql/lib/semmle/code/java/PrettyPrintAst.qll @@ -351,9 +351,9 @@ private class PpConditionalExpr extends PpAst, ConditionalExpr { override PpAst getChild(int i) { i = 0 and result = this.getCondition() or - i = 2 and result = this.getTrueExpr() + i = 2 and result = this.getThen() or - i = 4 and result = this.getFalseExpr() + i = 4 and result = this.getElse() } } diff --git a/java/ql/lib/semmle/code/java/controlflow/Guards.qll b/java/ql/lib/semmle/code/java/controlflow/Guards.qll index 95465849701..84536047483 100644 --- a/java/ql/lib/semmle/code/java/controlflow/Guards.qll +++ b/java/ql/lib/semmle/code/java/controlflow/Guards.qll @@ -315,13 +315,7 @@ private module GuardsInput implements SharedGuards::InputSig