A local thread pool is created and never shut down, so its threads outlive the function
What it finds
The threads of an executor from Executors.newFixedThreadPool and its kind run until the executor is shut down. One created in a function and dropped without shutdown() or close() keeps its threads, and can keep the program from exiting.
From the rule's source, executor_not_shut_down.rs.
fun run(tasks: List<Runnable>) { val pool = Executors.newFixedThreadPool(4)tx0 reports: the executor pool is never shut down tasks.forEach { pool.submit(it) } val other = Executors.newCachedThreadPool() tasks.forEach { other.submit(it) } other.shutdown() val handed = Executors.newSingleThreadExecutor() keep(handed)} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:executor-never-shut-down" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:executor-never-shut-down] reason="..."tx0 explain tx0/kotlin:executor-never-shut-down shows the same in the terminal. Found a false positive? Report it.