Skip to content

Commit 4b042f9

Browse files
committed
Kotlin: Add test cases for java/unreachable-catch-clause
1 parent b9f1cc5 commit 4b042f9

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| PartiallyMaskedCatchTest.kt:18:7:20:5 | catch (...) | This catch-clause is unreachable; it is masked $@. | PartiallyMaskedCatchTest.kt:16:7:18:5 | catch (...) | by a previous catch-clause for exceptions of type 'FileNotFoundException' |
2+
| PartiallyMaskedCatchTest.kt:28:7:30:5 | catch (...) | This catch-clause is unreachable; it is masked $@. | PartiallyMaskedCatchTest.kt:26:7:28:5 | catch (...) | by a previous catch-clause for exceptions of type 'FileNotFoundException' |
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) { // False positive
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) { // True positive
29+
println(e)
30+
}
31+
}

0 commit comments

Comments
 (0)