Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARKT-286 Fix S6619 false positives… #393

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,10 @@ private fun <E : Throwable> moo(exception: E) =
cachedCtor(exception) as E?
}

private class FooBar(
something: Any
) {
private val someString: String? = something as? String
val isString: Boolean
get() = someString != null // Compliant
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ class UselessNullCheckCheck : AbstractCheck() {
}

private fun KtBinaryExpression.operandComparedToNull(bc: BindingContext): KtExpression? {
val left = left?.predictRuntimeValueExpression(bc) ?: return null
val right = right?.predictRuntimeValueExpression(bc) ?: return null
val leftResolved = left?.predictRuntimeValueExpression(bc) ?: return null
val rightResolved = right?.predictRuntimeValueExpression(bc) ?: return null

return when {
left.isNull() -> right
right.isNull() -> left
leftResolved.isNull() -> right
rightResolved.isNull() -> left
else -> null
}
}
Expand Down