Skip to content

Commit 3264bbc

Browse files
authored
Merge pull request github#10962 from tamasvajk/kotlin-unreachable-catch
Kotlin: Exclude .kt files from `java/unreachable-catch-clause`
2 parents 7013663 + 0e4287e commit 3264bbc

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ predicate overlappingExceptions(RefType e1, RefType e2) {
8686

8787
from TryStmt try, int first, int second, RefType masking, RefType masked, string multiCatchMsg
8888
where
89+
try.getFile().isJavaSourceFile() and
8990
masking = caughtType(try, first) and
9091
masking.getAStrictAncestor() = masked and
9192
masked = caughtType(try, second) and

java/ql/test/kotlin/query-tests/PartiallyMaskedCatch/PartiallyMaskedCatch.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Likely Bugs/Statements/PartiallyMaskedCatch.ql
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
fun fn0() { throw java.io.IOException() }
2+
3+
fun fn1() {
4+
try {
5+
throw java.io.IOException()
6+
} catch (e: java.io.FileNotFoundException) {
7+
println(e)
8+
} catch (e: java.io.IOException) {
9+
println(e)
10+
}
11+
}
12+
13+
fun fn2() {
14+
try {
15+
fn0()
16+
} catch (e: java.io.FileNotFoundException) {
17+
println(e)
18+
} catch (e: java.io.IOException) {
19+
println(e)
20+
}
21+
}
22+
23+
fun fn3() {
24+
try {
25+
throw java.io.FileNotFoundException()
26+
} catch (e: java.io.FileNotFoundException) {
27+
println(e)
28+
} catch (e: java.io.IOException) { // TODO: False negative
29+
println(e)
30+
}
31+
}

0 commit comments

Comments
 (0)