Skip to content

Commit 65457cc

Browse files
JLLeitschuhsmowton
andauthored
Apply suggestions from code review
Co-authored-by: Chris Smowton <smowton@github.com>
1 parent 2e8b5f7 commit 65457cc

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
category: minorAnalysis
33
---
4-
* Add new method `CharacterLiteral.getStringifiedValue` which attempts to compute the
5-
`String.valueOf` compile time constant value of the expression.
4+
* Add new method `CompileTimeConstantExpr.getStringifiedValue` which attempts to compute the
5+
`String.valueOf` string rendering of a constant expression.

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,9 @@ class CompileTimeConstantExpr extends Expr {
201201
result = this.(StringLiteral).getValue()
202202
or
203203
(
204-
if this.(AddExpr).getAnOperand().getType() instanceof TypeString // If either operand type is already a String:
205-
then
206-
// Then the stringified version of the expression can be safely used as a String will be created.
207-
result =
208-
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringifiedValue() +
209-
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringifiedValue()
210-
else
211-
// Adding two literals of primitive type will not result in a String.
212-
result =
213-
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringValue() +
214-
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringValue()
204+
this.getType() instanceof TypeString and
205+
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringifiedValue() +
206+
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringifiedValue()
215207
)
216208
or
217209
// Ternary conditional, with compile-time constant condition.

0 commit comments

Comments
 (0)