Unused Flow

ID

kotlin.unused_flow

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Kotlin

Tags

concurrency, reliability, unused-code

Description

Reports Flow builders (flow {}, flowOf, emptyFlow, channelFlow {}, callbackFlow {}, asFlow) whose result is never consumed.

Rationale

suspend fun bad() {
    flowOf(1, 2, 3)           // FLAW
    flow { emit(1) }          // FLAW
}

A Flow is cold — no value is produced until a terminal operator (such as collect, toList, first) is attached. A builder call made as a bare expression statement constructs the flow, immediately drops it on the floor, and never emits anything. The work the developer intended to do never runs.

Remediation

suspend fun good() {
    flowOf(1, 2, 3).collect { println(it) }
}

Attach a terminal operator at the call site, capture the flow in a variable or return it from the function so callers can collect it. If the builder call really is a no-op, remove it.