@@ -327,12 +327,18 @@ private module ControlFlowGraphImpl {
327
327
)
328
328
}
329
329
330
+ private ThrowableType assertionError ( ) { result .hasQualifiedName ( "java.lang" , "AssertionError" ) }
331
+
330
332
/**
331
333
* Gets an exception type that may be thrown during execution of the
332
334
* body or the resources (if any) of `try`.
333
335
*/
334
336
private ThrowableType thrownInBody ( TryStmt try ) {
335
- exists ( AstNode n | mayThrow ( n , result ) |
337
+ exists ( AstNode n |
338
+ mayThrow ( n , result )
339
+ or
340
+ n instanceof AssertStmt and result = assertionError ( )
341
+ |
336
342
n .getEnclosingStmt ( ) .getEnclosingStmt + ( ) = try .getBlock ( ) or
337
343
n .( Expr ) .getParent * ( ) = try .getAResource ( )
338
344
)
@@ -394,10 +400,7 @@ private module ControlFlowGraphImpl {
394
400
exists ( LogicExpr logexpr |
395
401
logexpr .( BinaryExpr ) .getLeftOperand ( ) = b
396
402
or
397
- // Cannot use LogicExpr.getAnOperand or BinaryExpr.getAnOperand as they remove parentheses.
398
- logexpr .( BinaryExpr ) .getRightOperand ( ) = b and inBooleanContext ( logexpr )
399
- or
400
- logexpr .( UnaryExpr ) .getExpr ( ) = b and inBooleanContext ( logexpr )
403
+ logexpr .getAnOperand ( ) = b and inBooleanContext ( logexpr )
401
404
)
402
405
or
403
406
exists ( ConditionalExpr condexpr |
@@ -407,6 +410,8 @@ private module ControlFlowGraphImpl {
407
410
inBooleanContext ( condexpr )
408
411
)
409
412
or
413
+ exists ( AssertStmt assertstmt | assertstmt .getExpr ( ) = b )
414
+ or
410
415
exists ( SwitchExpr switch |
411
416
inBooleanContext ( switch ) and
412
417
switch .getAResult ( ) = b
@@ -672,8 +677,6 @@ private module ControlFlowGraphImpl {
672
677
this instanceof EmptyStmt
673
678
or
674
679
this instanceof LocalTypeDeclStmt
675
- or
676
- this instanceof AssertStmt
677
680
}
678
681
679
682
/** Gets child nodes in their order of execution. Indexing starts at either -1 or 0. */
@@ -744,8 +747,6 @@ private module ControlFlowGraphImpl {
744
747
or
745
748
index = 0 and result = this .( ThrowStmt ) .getExpr ( )
746
749
or
747
- index = 0 and result = this .( AssertStmt ) .getExpr ( )
748
- or
749
750
result = this .( RecordPatternExpr ) .getSubPattern ( index )
750
751
}
751
752
@@ -807,9 +808,12 @@ private module ControlFlowGraphImpl {
807
808
or
808
809
result = first ( n .( SynchronizedStmt ) .getExpr ( ) )
809
810
or
811
+ result = first ( n .( AssertStmt ) .getExpr ( ) )
812
+ or
810
813
result .asStmt ( ) = n and
811
814
not n instanceof PostOrderNode and
812
- not n instanceof SynchronizedStmt
815
+ not n instanceof SynchronizedStmt and
816
+ not n instanceof AssertStmt
813
817
or
814
818
result .asExpr ( ) = n and n instanceof SwitchExpr
815
819
}
@@ -1112,7 +1116,22 @@ private module ControlFlowGraphImpl {
1112
1116
// `return` statements give rise to a `Return` completion
1113
1117
last .asStmt ( ) = n .( ReturnStmt ) and completion = ReturnCompletion ( )
1114
1118
or
1115
- // `throw` statements or throwing calls give rise to ` Throw` completion
1119
+ exists ( AssertStmt assertstmt | assertstmt = n |
1120
+ // `assert` statements may complete normally - we use the `AssertStmt` itself
1121
+ // to represent this outcome
1122
+ last .asStmt ( ) = assertstmt and completion = NormalCompletion ( )
1123
+ or
1124
+ // `assert` statements may throw
1125
+ completion = ThrowCompletion ( assertionError ( ) ) and
1126
+ (
1127
+ last ( assertstmt .getMessage ( ) , last , NormalCompletion ( ) )
1128
+ or
1129
+ not exists ( assertstmt .getMessage ( ) ) and
1130
+ last ( assertstmt .getExpr ( ) , last , BooleanCompletion ( false , _) )
1131
+ )
1132
+ )
1133
+ or
1134
+ // `throw` statements or throwing calls give rise to `Throw` completion
1116
1135
exists ( ThrowableType tt | mayThrow ( n , tt ) |
1117
1136
last = n .getCfgNode ( ) and completion = ThrowCompletion ( tt )
1118
1137
)
@@ -1520,6 +1539,17 @@ private module ControlFlowGraphImpl {
1520
1539
exists ( int i | last ( s .getVariable ( i ) , n , completion ) and result = first ( s .getVariable ( i + 1 ) ) )
1521
1540
)
1522
1541
or
1542
+ // Assert statements:
1543
+ exists ( AssertStmt assertstmt |
1544
+ last ( assertstmt .getExpr ( ) , n , completion ) and
1545
+ completion = BooleanCompletion ( true , _) and
1546
+ result .asStmt ( ) = assertstmt
1547
+ or
1548
+ last ( assertstmt .getExpr ( ) , n , completion ) and
1549
+ completion = BooleanCompletion ( false , _) and
1550
+ result = first ( assertstmt .getMessage ( ) )
1551
+ )
1552
+ or
1523
1553
// When expressions:
1524
1554
exists ( WhenExpr whenexpr |
1525
1555
n .asExpr ( ) = whenexpr and
0 commit comments