Merge pull request #10962 from tamasvajk/kotlin-unreachable-catch

Kotlin: Exclude .kt files from `java/unreachable-catch-clause`
This commit is contained in:
Tamás Vajk
2022-10-25 15:01:25 +02:00
committed by GitHub
4 changed files with 33 additions and 0 deletions

View File

@@ -86,6 +86,7 @@ predicate overlappingExceptions(RefType e1, RefType e2) {
from TryStmt try, int first, int second, RefType masking, RefType masked, string multiCatchMsg
where
try.getFile().isJavaSourceFile() and
masking = caughtType(try, first) and
masking.getAStrictAncestor() = masked and
masked = caughtType(try, second) and

View File

@@ -0,0 +1 @@
Likely Bugs/Statements/PartiallyMaskedCatch.ql

View File

@@ -0,0 +1,31 @@
fun fn0() { throw java.io.IOException() }
fun fn1() {
try {
throw java.io.IOException()
} catch (e: java.io.FileNotFoundException) {
println(e)
} catch (e: java.io.IOException) {
println(e)
}
}
fun fn2() {
try {
fn0()
} catch (e: java.io.FileNotFoundException) {
println(e)
} catch (e: java.io.IOException) {
println(e)
}
}
fun fn3() {
try {
throw java.io.FileNotFoundException()
} catch (e: java.io.FileNotFoundException) {
println(e)
} catch (e: java.io.IOException) { // TODO: False negative
println(e)
}
}