Skip to content

Commit cd8ac1a

Browse files
authored
Merge pull request github#10720 from tamasvajk/kotlin-equals-fix
Kotlin: Consider `::class` type check in `java/unchecked-cast-in-equals`
2 parents 9f2f6ac + 51f9314 commit cd8ac1a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

java/ql/src/Likely Bugs/Comparison/MissingInstanceofInEquals.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ predicate hasTypeTest(Variable v) {
3030
or
3131
any(SafeCastExpr sce).getExpr() = v.getAnAccess()
3232
or
33+
any(ClassExpr c).getExpr() = v.getAnAccess()
34+
or
3335
exists(MethodAccess ma |
3436
ma.getMethod().getName() = "getClass" and
3537
ma.getQualifier() = v.getAnAccess()

java/ql/test/kotlin/query-tests/MissingInstanceofInEquals/Test.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ data class E(val x: Int) {
55
return (other as? E)?.x == this.x
66
}
77
}
8+
9+
data class F(val x: Int) {
10+
override fun equals(other: Any?): Boolean {
11+
return other != null && other::class == this::class
12+
}
13+
}

0 commit comments

Comments
 (0)