detekt: NullPointerException in IgnoredReturnValue rule in version 1.23.0.
Expected Behavior
IgnoredReturnValue rule should check successfully.
Observed Behavior
The rule crashes during ./gradlew detekt
with java.lang.NullPointerException
when it is trying find package because containingDeclaration in DeclarationDescriptor is null.
Caused by: java.lang.NullPointerException
at org.jetbrains.kotlin.backend.common.serialization.LegacyDescriptorUtilsKt.findPackage(LegacyDescriptorUtils.kt:29)
at io.gitlab.arturbosch.detekt.rules.bugs.IgnoredReturnValue.visitCallExpression(IgnoredReturnValue.kt:118)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitCallExpression(KtVisitorVoid.java:811)
at org.jetbrains.kotlin.psi.KtVisitorVoid.visitCallExpression(KtVisitorVoid.java:21)
...
Steps to Reproduce
- update detekt to 1.23.0.
- run ./gradlew detekt
Context
Before updating of the version this rule was checking correctly. Then I update to 1.23.0 and this rule is crashing now.
So it seems, that the problem in method which get local contacts via Cursor inside kotlinx.coroutines.flow.callbackFlow
When I comment few strings as in example, it is checking correctly.
callbackFlow {
// getting cursore
// val contentObserver =
// object : ContentObserver(createHandler()) {
//
// override fun onChange(selfChange: Boolean) {
// launch {
// if (cursor != null) {
// send(cursor)
// }
// }
// }
// }
//
// cursor?.registerContentObserver(contentObserver)
//
// awaitClose {
// cursor?.unregisterContentObserver(contentObserver)
// cursor?.close()
// }
}
Your Environment
- Version of detekt used: 1.23.0
- Version of Gradle used (if applicable): 8.0.1
- Operating System and version: Mac OS X 13.0 (aarch64)
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 1
- Comments: 17 (9 by maintainers)
Sorry for misleading you, you need to enable
debug
for detekt which doesn’t use that flag (but probably should…)I’m able to reproduce the issue. And I have no idea why but if I update the gradle version to the last one it works again:
./gradlew wrapper --gradle-version 8.2.1
Could you check if that happens to you too?
Hey! 👋 I’ve encountered this issue as well, and for me it reproduces with a certain combination of dependencies 🤔 I’ve quickly drafted this repo as an example: https://github.com/diastremskii/detekt-issue-6175. In this repo,
./gradlew detektMain
fails withCertainly, there must be a way to reproduce it without pulling in SLF4J and Arrow-kt and I’m sorry for building not very clean example, but at least it captures and reproduces the issue.
Hi, @maxsdev the above rule only run when type resolution is enabled. But in the steps to repro you gave
./gradlew detekt
command which runs without type resolution(henceIgnoredReturnValue
will be skipped). Also, can you clarifyWhen I comment few strings as in example, it is checking correctly.
is provided example running correctly by the rule.If you can provide a failing TC that would be great