Skip to content

Commit d5cdfc6

Browse files
authored
Merge pull request #20092 from aschackmull/java/joinorder2
Java: Improve more join-orders
2 parents fbee6bb + 46ebf50 commit d5cdfc6

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

java/ql/src/Likely Bugs/Collections/ArrayIndexOutOfBounds.ql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import semmle.code.java.dataflow.SSA
1818
import semmle.code.java.dataflow.RangeUtils
1919
import semmle.code.java.dataflow.RangeAnalysis
2020

21+
pragma[nomagic]
22+
predicate ssaArrayLengthBound(SsaVariable arr, Bound b) {
23+
exists(FieldAccess len |
24+
len.getField() instanceof ArrayLengthField and
25+
len.getQualifier() = arr.getAUse() and
26+
b.getExpr() = len
27+
)
28+
}
29+
2130
/**
2231
* Holds if the index expression of `aa` is less than or equal to the array length plus `k`.
2332
*/
@@ -27,12 +36,8 @@ predicate boundedArrayAccess(ArrayAccess aa, int k) {
2736
aa.getArray() = arr.getAUse() and
2837
bounded(index, b, delta, true, _)
2938
|
30-
exists(FieldAccess len |
31-
len.getField() instanceof ArrayLengthField and
32-
len.getQualifier() = arr.getAUse() and
33-
b.getExpr() = len and
34-
k = delta
35-
)
39+
ssaArrayLengthBound(arr, b) and
40+
k = delta
3641
or
3742
exists(ArrayCreationExpr arraycreation | arraycreation = getArrayDef(arr) |
3843
k = delta and

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)