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

False positive: UnconditionalJumpStatementInLoop with elvis operator ?: #2388

BraisGabin opened this issue Mar 2, 2020 · 5 comments


Copy link

Expected Behavior

The elvis operator is a conditional so code like this should be accepted:

for (resource in"META-INF/MANIFEST.MF")) {
    return runCatching { readVersion(resource) }.getOrNull() ?: continue

Observed Behavior

It fails


We found this false positive at #2387

Your Environment

  • Version of detekt used: 1.6.0
Copy link

schalkms commented Mar 3, 2020

Fixed by a9bb93e

@schalkms schalkms closed this as completed Mar 3, 2020
Copy link

michalsikora-silvair commented Sep 28, 2021

I'm getting this in 1.18.1.

fun function(items: List<Int?>): String? {
    for (item in items) {
        val intItem = item ?: continue
        return intItem.toString()
    return null

Unless it is different due to return in different statement. I can't inline it in the real code as there is more data processing in between.


Yup, seems that return in the same line fixes it. Should I open different issue?

Copy link
Member Author

Yes, please, open a new issue.

Copy link

Will do. :)

Copy link

Filed in #4134.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

5 participants