Kotlin: Exclude .kt files from java/unreachable-catch-clause

This commit is contained in:
Tamas Vajk
2022-10-25 11:06:48 +02:00
parent 4b042f9770
commit 0e4287e378
3 changed files with 3 additions and 4 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

@@ -1,2 +0,0 @@
| 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' |
| 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' |

View File

@@ -15,7 +15,7 @@ fun fn2() {
fn0()
} catch (e: java.io.FileNotFoundException) {
println(e)
} catch (e: java.io.IOException) { // False positive
} catch (e: java.io.IOException) {
println(e)
}
}
@@ -25,7 +25,7 @@ fun fn3() {
throw java.io.FileNotFoundException()
} catch (e: java.io.FileNotFoundException) {
println(e)
} catch (e: java.io.IOException) { // True positive
} catch (e: java.io.IOException) { // TODO: False negative
println(e)
}
}