kotlin:S6311 raises a false-positive for Android ViewModel coroutines usage

Make sure to read this post before raising a thread here:

Then tell us:

class MyViewModel() : ViewModel() {

    private val _actions = MutableSharedFlow<Unit>()
    val actions: Flow<Unit> = _actions

    fun nonSuspendingFunction() {
        viewModelScope.launch {
            _actions.emit(Unit)
        }
    }
}

Hey Jonny,

Thanks for letting us know.

kotlin:S6311 has a bug currently, which causes it to raise an issue in cases such as the snippet you gave. There is a fix underway and it should be corrected by the next release.

1 Like

Hello,

I just wanted to provide an update about this topic. The fix is live on SonarQube Cloud and was shipped with SonarQube 2025.2. If you still experience issues with this rule, feel free to reach out.

2 Likes