Skip to content

Commit 496cae7

Browse files
committed
Revert 8325, Add CharacterLiteral to CompileTimeConstantExpr.getStringValue
As pointed out in 8325's thread, this breaks the corner case of char-literal addition and the convention that getStringValue only applies to String-typed constants.
1 parent a8b2805 commit 496cae7

File tree

7 files changed

+1
-33
lines changed

7 files changed

+1
-33
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ class CompileTimeConstantExpr extends Expr {
168168
string getStringValue() {
169169
result = this.(StringLiteral).getValue()
170170
or
171-
result = this.(CharacterLiteral).getValue()
172-
or
173171
result =
174172
this.(AddExpr).getLeftOperand().(CompileTimeConstantExpr).getStringValue() +
175173
this.(AddExpr).getRightOperand().(CompileTimeConstantExpr).getStringValue()

java/ql/test/library-tests/constants/CompileTimeConstantExpr.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@
1515
| constants/Constants.java:20:22:20:22 | 5 |
1616
| constants/Constants.java:20:27:20:27 | 1 |
1717
| constants/Constants.java:20:31:20:31 | 2 |
18-
| constants/Constants.java:21:22:21:24 | 'a' |

java/ql/test/library-tests/constants/PrintAst.expected

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ constants/Constants.java:
6666
# 20| 1: [IntegerLiteral] 5
6767
# 20| 1: [IntegerLiteral] 1
6868
# 20| 2: [IntegerLiteral] 2
69-
# 21| 11: [LocalVariableDeclStmt] var ...;
70-
# 21| 0: [TypeAccess] char
71-
# 21| 1: [LocalVariableDeclExpr] charLiteral
72-
# 21| 0: [CharacterLiteral] 'a'
73-
# 23| 12: [ReturnStmt] return ...
69+
# 22| 11: [ReturnStmt] return ...
7470
constants/Initializers.java:
7571
# 0| [CompilationUnit] Initializers
7672
# 3| 1: [Class] Initializers
@@ -516,13 +512,3 @@ constants/Values.java:
516512
# 90| 0: [TypeAccess] int
517513
# 90| 1: [LocalVariableDeclExpr] var_nonfinald_local
518514
# 90| 0: [VarAccess] var_field
519-
# 91| 68: [LocalVariableDeclStmt] var ...;
520-
# 91| 0: [TypeAccess] String
521-
# 91| 1: [LocalVariableDeclExpr] concatenatedString
522-
# 91| 0: [StringLiteral] "a" + "b"
523-
# 92| 69: [LocalVariableDeclStmt] var ...;
524-
# 92| 0: [TypeAccess] String
525-
# 92| 1: [LocalVariableDeclExpr] concatenatedChar
526-
# 92| 0: [AddExpr] ... + ...
527-
# 92| 0: [StringLiteral] "ab"
528-
# 92| 1: [CharacterLiteral] 'c'

java/ql/test/library-tests/constants/constants/Constants.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ void constants(final int notConstant) {
1818
int paren = (12);
1919
String string = "a string";
2020
int ternary = (3 < 5) ? 1 : 2;
21-
char charLiteral = 'a';
2221

2322
return;
2423
}

java/ql/test/library-tests/constants/constants/Values.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,5 @@ void values(final int notConstant) {
8888
int var_local = final_local; //42
8989
int var_param = notConstant; //Not constant
9090
int var_nonfinald_local = var_field; //Not constant
91-
String concatenatedString = "a" + "b"; //ab
92-
String concatenatedChar = "ab" + 'c'; //abc
9391
}
9492
}

java/ql/test/library-tests/constants/getStringValue.expected

Lines changed: 0 additions & 3 deletions
This file was deleted.

java/ql/test/library-tests/constants/getStringValue.ql

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)