Skip to content

Commit 46ebf50

Browse files
committed
Java: Improve join-order by controlling magic and breaking up TCs.
1 parent ca8fe03 commit 46ebf50

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

java/ql/src/Likely Bugs/Statements/PartiallyMaskedCatch.ql

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,34 @@
1515

1616
import java
1717

18+
pragma[nomagic]
19+
predicate mayThrow(Stmt s, RefType rt) {
20+
s.(ThrowStmt).getExpr().getType() = rt
21+
or
22+
exists(Call call |
23+
call.getEnclosingStmt() = s and
24+
call.getCallee().getAnException().getType() = rt
25+
)
26+
}
27+
28+
pragma[nomagic]
29+
predicate caughtBy(TryStmt try, Stmt s, RefType rt) {
30+
mayThrow(s, rt) and
31+
s.getEnclosingStmt+() = try.getBlock() and
32+
caughtType(try, _).hasSubtype*(rt)
33+
}
34+
35+
pragma[nomagic]
36+
predicate nestedTry(TryStmt outer, TryStmt inner) { inner.getEnclosingStmt+() = outer.getBlock() }
37+
1838
/**
1939
* Exceptions of type `rt` thrown from within statement `s` are caught by an inner try block
2040
* and are therefore not propagated to the outer try block `t`.
2141
*/
2242
private predicate caughtInside(TryStmt t, Stmt s, RefType rt) {
23-
exists(TryStmt innerTry | innerTry.getEnclosingStmt+() = t.getBlock() |
24-
s.getEnclosingStmt+() = innerTry.getBlock() and
25-
caughtType(innerTry, _).hasSubtype*(rt)
43+
exists(TryStmt innerTry |
44+
nestedTry(t, innerTry) and
45+
caughtBy(innerTry, s, rt)
2646
)
2747
}
2848

0 commit comments

Comments
 (0)