Skip to content
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
11 changes: 10 additions & 1 deletion java/ql/lib/semmle/code/java/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,15 @@ class CharacterLiteral extends Literal, @characterliteral {
override string getAPrimaryQlClass() { result = "CharacterLiteral" }
}

/** A string literal. For example, `"hello world"`. */
/**
* A string literal or text block (Java 15 feature). For example, `"hello world"`
* or
* ```java
* """
* Text with "quotes"
* """
* ```
*/
class StringLiteral extends Literal, @stringliteral {
/**
* Gets the literal string without the quotes.
Expand All @@ -734,6 +742,7 @@ class StringLiteral extends Literal, @stringliteral {

/** The null literal, written `null`. */
class NullLiteral extends Literal, @nullliteral {
// Override these predicates because the inherited ones have no result
override string getLiteral() { result = "null" }

override string getValue() { result = "null" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package booleanLiterals;

public class BooleanLiterals {
boolean[] booleans = {
true,
false,
// Using Unicode escapes (which are handled during pre-processing)
\u0074\u0072\u0075\u0065, // true
};

// The operation expression (e.g. `&&`) is not a literal
boolean[] logicOperations = {
true && true,
false && false,
true && false,
true || true,
false || false,
true || false,
};

Object[] nonBooleanLiterals = {
"true",
"false",
1,
0,
Boolean.TRUE,
Boolean.FALSE,
};

boolean nonLiteral;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
| BooleanLiterals.java:5:3:5:6 | true | true | true |
| BooleanLiterals.java:6:3:6:7 | false | false | false |
| BooleanLiterals.java:8:8:8:26 | 4\\u0072\\u0075\\u0065 | true | true |
| BooleanLiterals.java:13:3:13:6 | true | true | true |
| BooleanLiterals.java:13:11:13:14 | true | true | true |
| BooleanLiterals.java:14:3:14:7 | false | false | false |
| BooleanLiterals.java:14:12:14:16 | false | false | false |
| BooleanLiterals.java:15:3:15:6 | true | true | true |
| BooleanLiterals.java:15:11:15:15 | false | false | false |
| BooleanLiterals.java:16:3:16:6 | true | true | true |
| BooleanLiterals.java:16:11:16:14 | true | true | true |
| BooleanLiterals.java:17:3:17:7 | false | false | false |
| BooleanLiterals.java:17:12:17:16 | false | false | false |
| BooleanLiterals.java:18:3:18:6 | true | true | true |
| BooleanLiterals.java:18:11:18:15 | false | false | false |
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package charLiterals;

public class CharLiterals {
char[] chars = {
'a',
'\u0061', // 'a'
'\u0000',
'\uFFFF',
'\ufFfF',
'\0',
'\n',
'"',
'\\',
'\'',
'\123', // octal escape sequence for 'S'
'\uD800', // high surrogate
'\uDC00', // low surrogate
// Using Unicode escapes (which are handled during pre-processing)
'\u005C\u005C', // escaped backslash
'\u005C\u0027', // escaped single quote
\u0027a\u0027, // 'a'
};

// + and - are not part of the literal
int[] charsWithSign = {
+'a',
-'a',
};

// The operation expression (e.g. `+`) is not a literal
int[] numericOperations = {
'a' + 'b',
};

Object[] nonCharLiterals = {
"a",
"",
"\uD800\uDC00", // surrogate pair
0,
Character.MIN_VALUE,
};

char nonLiteral;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
| CharLiterals.java:5:3:5:5 | 'a' | a |
| CharLiterals.java:6:3:6:10 | '\\u0061' | a |
| CharLiterals.java:7:3:7:10 | '\\u0000' | \u0000 |
| CharLiterals.java:8:3:8:10 | '\\uFFFF' | \uffff |
| CharLiterals.java:9:3:9:10 | '\\ufFfF' | \uffff |
| CharLiterals.java:10:3:10:6 | '\\0' | \u0000 |
| CharLiterals.java:11:3:11:6 | '\\n' | \n |
| CharLiterals.java:12:3:12:5 | '"' | " |
| CharLiterals.java:13:3:13:6 | '\\\\' | \\ |
| CharLiterals.java:14:3:14:6 | '\\'' | ' |
| CharLiterals.java:15:3:15:8 | '\\123' | S |
| CharLiterals.java:16:3:16:10 | '\\uD800' | \ufffd |
| CharLiterals.java:17:3:17:10 | '\\uDC00' | \ufffd |
| CharLiterals.java:19:3:19:16 | '\\u005C\\u005C' | \\ |
| CharLiterals.java:20:3:20:16 | '\\u005C\\u0027' | ' |
| CharLiterals.java:21:8:21:15 | 7a\\u0027 | a |
| CharLiterals.java:26:4:26:6 | 'a' | a |
| CharLiterals.java:27:4:27:6 | 'a' | a |
| CharLiterals.java:32:3:32:5 | 'a' | a |
| CharLiterals.java:32:9:32:11 | 'b' | b |
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package doubleLiterals;

public class DoubleLiterals {
double[] doubles = {
0.0,
0d,
0D,
.0d,
.0,
0.,
1.234567890123456789,
1.55555555555555555555,
// From the JLS
1e1,
1.7976931348623157E308,
0x1.f_ffff_ffff_ffffP+1023,
4.9e-324,
0x0.0_0000_0000_0001P-1022,
0x1.0P-1074,
// Using Unicode escapes (which are handled during pre-processing)
\u0030\u002E\u0030, // 0.0
};

// + and - are not part of the literal
double[] doublesWithSign = {
+0.0,
-0.0,
+1.0,
-1.0,
+1.7976931348623157E308,
-1.7976931348623157E308,
};

// The operation expression (e.g. `+`) is not a literal
double[] numericOperations = {
0.0 + 0.0,
0.0 / 0.0,
};

Object[] nonDoubleLiterals = {
"0",
'0',
0,
0.0f,
(double) 0.0f,
Double.MIN_VALUE,
};

double nonLiteral;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
| DoubleLiterals.java:5:3:5:5 | 0.0 | 0.0 | 0.0 |
| DoubleLiterals.java:6:3:6:4 | 0d | 0.0 | 0.0 |
| DoubleLiterals.java:7:3:7:4 | 0D | 0.0 | 0.0 |
| DoubleLiterals.java:8:3:8:5 | .0d | 0.0 | 0.0 |
| DoubleLiterals.java:9:3:9:4 | .0 | 0.0 | 0.0 |
| DoubleLiterals.java:10:3:10:4 | 0. | 0.0 | 0.0 |
| DoubleLiterals.java:11:3:11:22 | 1.234567890123456789 | 1.2345678901234567 | 1.2345678901234567 |
| DoubleLiterals.java:12:3:12:24 | 1.55555555555555555555 | 1.5555555555555556 | 1.5555555555555556 |
| DoubleLiterals.java:14:3:14:5 | 1e1 | 10.0 | 10.0 |
| DoubleLiterals.java:15:3:15:24 | 1.7976931348623157E308 | 1.7976931348623157E308 | 1.7976931348623157E308 |
| DoubleLiterals.java:16:3:16:28 | 0x1.f_ffff_ffff_ffffP+1023 | 1.7976931348623157E308 | 1.7976931348623157E308 |
| DoubleLiterals.java:17:3:17:10 | 4.9e-324 | 4.9E-324 | 4.9E-324 |
| DoubleLiterals.java:18:3:18:28 | 0x0.0_0000_0000_0001P-1022 | 4.9E-324 | 4.9E-324 |
| DoubleLiterals.java:19:3:19:13 | 0x1.0P-1074 | 4.9E-324 | 4.9E-324 |
| DoubleLiterals.java:21:8:21:20 | 0\\u002E\\u0030 | 0.0 | 0.0 |
| DoubleLiterals.java:26:4:26:6 | 0.0 | 0.0 | 0.0 |
| DoubleLiterals.java:27:4:27:6 | 0.0 | 0.0 | 0.0 |
| DoubleLiterals.java:28:4:28:6 | 1.0 | 1.0 | 1.0 |
| DoubleLiterals.java:29:4:29:6 | 1.0 | 1.0 | 1.0 |
| DoubleLiterals.java:30:4:30:25 | 1.7976931348623157E308 | 1.7976931348623157E308 | 1.7976931348623157E308 |
| DoubleLiterals.java:31:4:31:25 | 1.7976931348623157E308 | 1.7976931348623157E308 | 1.7976931348623157E308 |
| DoubleLiterals.java:36:3:36:5 | 0.0 | 0.0 | 0.0 |
| DoubleLiterals.java:36:9:36:11 | 0.0 | 0.0 | 0.0 |
| DoubleLiterals.java:37:3:37:5 | 0.0 | 0.0 | 0.0 |
| DoubleLiterals.java:37:9:37:11 | 0.0 | 0.0 | 0.0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package floatLiterals;

public class FloatLiterals {
float[] floats = {
0.0f,
0f,
.0f,
0.f,
1_0_0.0f,
1.234567890123456789f,
1.55555555555555555555f,
// From the JLS
1e1f,
3.4028235e38f,
0x1.fffffeP+127f,
1.4e-45f,
0x0.000002P-126f,
0x1.0P-149f,
// Using Unicode escapes (which are handled during pre-processing)
\u0030\u002E\u0030\u0066, // 0.0f
};

// + and - are not part of the literal
float[] floatsWithSign = {
+0.f,
-0.f,
+1.0f,
-1.0f,
+3.4028235e38f,
-3.4028235e38f,
};

// The operation expression (e.g. `+`) is not a literal
float[] numericOperations = {
0.0f + 0.0f,
0.0f / 0.0f,
};

Object[] nonFloatLiterals = {
"0f",
'0',
0,
0.0,
(float) 0.0,
Float.MIN_VALUE,
};

float nonLiteral;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
| FloatLiterals.java:5:3:5:6 | 0.0f | 0.0 | 0.0 |
| FloatLiterals.java:6:3:6:4 | 0f | 0.0 | 0.0 |
| FloatLiterals.java:7:3:7:5 | .0f | 0.0 | 0.0 |
| FloatLiterals.java:8:3:8:5 | 0.f | 0.0 | 0.0 |
| FloatLiterals.java:9:3:9:10 | 1_0_0.0f | 100.0 | 100.0 |
| FloatLiterals.java:10:3:10:23 | 1.234567890123456789f | 1.2345679 | 1.2345679 |
| FloatLiterals.java:11:3:11:25 | 1.55555555555555555555f | 1.5555556 | 1.5555556 |
| FloatLiterals.java:13:3:13:6 | 1e1f | 10.0 | 10.0 |
| FloatLiterals.java:14:3:14:15 | 3.4028235e38f | 3.4028235E38 | 3.4028235E38 |
| FloatLiterals.java:15:3:15:18 | 0x1.fffffeP+127f | 3.4028235E38 | 3.4028235E38 |
| FloatLiterals.java:16:3:16:10 | 1.4e-45f | 1.4E-45 | 1.4E-45 |
| FloatLiterals.java:17:3:17:18 | 0x0.000002P-126f | 1.4E-45 | 1.4E-45 |
| FloatLiterals.java:18:3:18:13 | 0x1.0P-149f | 1.4E-45 | 1.4E-45 |
| FloatLiterals.java:20:8:20:26 | 0\\u002E\\u0030\\u0066 | 0.0 | 0.0 |
| FloatLiterals.java:25:4:25:6 | 0.f | 0.0 | 0.0 |
| FloatLiterals.java:26:4:26:6 | 0.f | 0.0 | 0.0 |
| FloatLiterals.java:27:4:27:7 | 1.0f | 1.0 | 1.0 |
| FloatLiterals.java:28:4:28:7 | 1.0f | 1.0 | 1.0 |
| FloatLiterals.java:29:4:29:16 | 3.4028235e38f | 3.4028235E38 | 3.4028235E38 |
| FloatLiterals.java:30:4:30:16 | 3.4028235e38f | 3.4028235E38 | 3.4028235E38 |
| FloatLiterals.java:35:3:35:6 | 0.0f | 0.0 | 0.0 |
| FloatLiterals.java:35:10:35:13 | 0.0f | 0.0 | 0.0 |
| FloatLiterals.java:36:3:36:6 | 0.0f | 0.0 | 0.0 |
| FloatLiterals.java:36:10:36:13 | 0.0f | 0.0 | 0.0 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package integerLiterals;

public class IntegerLiterals {
int[] ints = {
0,
1,
0_0,
0___0,
0_12, // octal
0X012, // hex
0xaBcDeF, // hex
0B11, // binary
0x80000000,
2147483647,
-2147483648, // special case: sign is part of the literal
// From the JLS
0x7fff_ffff,
0177_7777_7777, // octal
0b0111_1111_1111_1111_1111_1111_1111_1111, // binary
0x8000_0000,
0200_0000_0000,
0b1000_0000_0000_0000_0000_0000_0000_0000,
0xffff_ffff,
0377_7777_7777,
0b1111_1111_1111_1111_1111_1111_1111_1111,
// Using Unicode escapes (which are handled during pre-processing)
\u0030, // 0
};

// + and - are not part of the literal
int[] intsWithSign = {
+0,
-0,
+1,
-1,
+2147483647,
};

// The operation expression (e.g. `+`) is not a literal
int[] numericOperations = {
1 + 1,
0 / 0,
};

Object[] nonIntLiterals = {
"0",
'0',
0L,
(int) 0L,
0.0,
(int) 0.0,
Integer.MIN_VALUE,
'a' + 'b', // result is int 195, but this is not a literal
};

int nonLiteral;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
| IntegerLiterals.java:5:3:5:3 | 0 | 0 | 0 |
| IntegerLiterals.java:6:3:6:3 | 1 | 1 | 1 |
| IntegerLiterals.java:7:3:7:5 | 0_0 | 0 | 0 |
| IntegerLiterals.java:8:3:8:7 | 0___0 | 0 | 0 |
| IntegerLiterals.java:9:3:9:6 | 0_12 | 10 | 10 |
| IntegerLiterals.java:10:3:10:7 | 0X012 | 18 | 18 |
| IntegerLiterals.java:11:3:11:10 | 0xaBcDeF | 11259375 | 11259375 |
| IntegerLiterals.java:12:3:12:6 | 0B11 | 3 | 3 |
| IntegerLiterals.java:13:3:13:12 | 0x80000000 | -2147483648 | -2147483648 |
| IntegerLiterals.java:14:3:14:12 | 2147483647 | 2147483647 | 2147483647 |
| IntegerLiterals.java:15:3:15:13 | -2147483648 | -2147483648 | -2147483648 |
| IntegerLiterals.java:17:3:17:13 | 0x7fff_ffff | 2147483647 | 2147483647 |
| IntegerLiterals.java:18:3:18:16 | 0177_7777_7777 | 2147483647 | 2147483647 |
| IntegerLiterals.java:19:3:19:43 | 0b0111_1111_1111_1111_1111_1111_1111_1111 | 2147483647 | 2147483647 |
| IntegerLiterals.java:20:3:20:13 | 0x8000_0000 | -2147483648 | -2147483648 |
| IntegerLiterals.java:21:3:21:16 | 0200_0000_0000 | -2147483648 | -2147483648 |
| IntegerLiterals.java:22:3:22:43 | 0b1000_0000_0000_0000_0000_0000_0000_0000 | -2147483648 | -2147483648 |
| IntegerLiterals.java:23:3:23:13 | 0xffff_ffff | -1 | -1 |
| IntegerLiterals.java:24:3:24:16 | 0377_7777_7777 | -1 | -1 |
| IntegerLiterals.java:25:3:25:43 | 0b1111_1111_1111_1111_1111_1111_1111_1111 | -1 | -1 |
| IntegerLiterals.java:27:8:27:8 | 0 | 0 | 0 |
| IntegerLiterals.java:32:4:32:4 | 0 | 0 | 0 |
| IntegerLiterals.java:33:4:33:4 | 0 | 0 | 0 |
| IntegerLiterals.java:34:4:34:4 | 1 | 1 | 1 |
| IntegerLiterals.java:35:4:35:4 | 1 | 1 | 1 |
| IntegerLiterals.java:36:4:36:13 | 2147483647 | 2147483647 | 2147483647 |
| IntegerLiterals.java:41:3:41:3 | 1 | 1 | 1 |
| IntegerLiterals.java:41:7:41:7 | 1 | 1 | 1 |
| IntegerLiterals.java:42:3:42:3 | 0 | 0 | 0 |
| IntegerLiterals.java:42:7:42:7 | 0 | 0 | 0 |
3 changes: 0 additions & 3 deletions java/ql/test/library-tests/literals/literalBoolean.expected

This file was deleted.

10 changes: 0 additions & 10 deletions java/ql/test/library-tests/literals/literalChar.expected

This file was deleted.

Loading