Skip to content

Commit c0f8973

Browse files
committed
Add test for extracting a Java AST with an error expression
Also note that ErrorExpr can occur outside upgrade/downgrade scripts
1 parent 8aeb9b9 commit c0f8973

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ class ExprParent extends @exprparent, Top { }
276276
* An error expression.
277277
*
278278
* These may be generated by upgrade or downgrade scripts when databases
279-
* cannot be fully converted.
279+
* cannot be fully converted, or generated by the extractor when extracting
280+
* source code containing errors.
280281
*/
281282
class ErrorExpr extends Expr, @errorexpr {
282283
override string toString() { result = "<error expr>" }
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Test.java:
2+
# 0| [CompilationUnit] Test
3+
# 1| 1: [Class] Test
4+
# 3| 2: [Method] yield
5+
# 3| 3: [TypeAccess] int
6+
#-----| 4: (Parameters)
7+
# 3| 0: [Parameter] x
8+
# 3| 0: [TypeAccess] int
9+
# 3| 5: [BlockStmt] { ... }
10+
# 3| 0: [ReturnStmt] return ...
11+
# 3| 0: [VarAccess] x
12+
# 5| 3: [Method] secondCall
13+
# 5| 3: [TypeAccess] void
14+
# 5| 5: [BlockStmt] { ... }
15+
# 7| 4: [Method] yieldWrapper
16+
# 7| 3: [TypeAccess] int
17+
#-----| 4: (Parameters)
18+
# 7| 0: [Parameter] x
19+
# 7| 0: [TypeAccess] int
20+
# 7| 5: [BlockStmt] { ... }
21+
# 8| 0: [LocalVariableDeclStmt] var ...;
22+
# 8| 0: [TypeAccess] int
23+
# 8| 1: [LocalVariableDeclExpr] ret
24+
# 8| 0: [ErrorExpr] <error expr>
25+
# 8| 0: [MethodAccess] yield(...)
26+
# 8| 0: [VarAccess] x
27+
# 9| 1: [ExprStmt] <Expr>;
28+
# 9| 0: [MethodAccess] secondCall(...)
29+
# 10| 2: [ReturnStmt] return ...
30+
# 10| 0: [VarAccess] ret
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle/code/java/PrintAst.ql
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Test {
2+
3+
public int yield(int x) { return x; }
4+
5+
public void secondCall() { }
6+
7+
public int yieldWrapper(int x) {
8+
int ret = yield(x);
9+
secondCall();
10+
return ret;
11+
}
12+
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --no-strict-javac-errors --javac-args -source 17 -target 17

0 commit comments

Comments
 (0)