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
2 False positives for nullable parameter CanBeNonNullable
#4677
Comments
Thanks for the detailed report @eygraber 🙏 Is this a regression? Could you check with 1.19.x if the issue is happening? |
The first one is a regression. I fix it in #4686. I don't get what's the problem in the second. |
Thanks for fixing the first one 💪 Sorry I left the context out of the second one. The issue is that |
I was able to repro the second issue by running |
Thanks for the reproducer! But that's working as expected. If a function only does something if a value is not Does that have sense to you? Am I missing something? |
That does make sense, but it is not the case in my project. However it seems like it's related to #4676 because it relates to a ViewBinding property. So where in my repro it is:
in my project it looks more like:
where the |
I tested assignment without ViewBinding and it still violates
|
I reduced your example: class CanBeNotNullFalsePositive {
private var isVisible: Boolean = false
fun setField(text: String?) {
isVisible = text?.also { println(text) } != null
}
} This raises an issue but it shouldn't. The strange part is that this code doesn't raise any issue: class CanBeNotNullFalsePositive {
private var isVisible: Boolean = false
fun setField(text: String?) {
isVisible = text != null
}
} |
Looks like 1.21.0-RC1 resolved this |
Closing as per this 👍 We can close if this is not the case anymore |
Looks like both of my issues are back in 1.22.0. Or maybe I had disabled them, forgot, and now re-enabled them? |
Here's a repro for one of them. I copied it from my project and sanitized it, so I'm not sure what the minimum repro is here. The error is:
And the repro is:
|
Can we create a new issue for those? I personally pay less attention to closed issues + they're harder to discover if someone else on .22 had the same issue as you had. |
Using detekt 1.20.0-RC2
The first issue can be reprod with:
I can't repro the second issue easily. This code doesn't repro the issue, but it mirrors the structure of the code in my project:
The text was updated successfully, but these errors were encountered: