A Thread object is passed where only a Runnable task is needed
What it finds
new Thread(worker) and executor.submit(worker) with worker a Thread use it only as a Runnable: its run is called on another thread, while the Thread object itself is never started, so its name, priority, daemon flag and uncaught exception handler have no effect.
Reported is a variable declared as a Thread, or a new Thread(...), passed to the constructor of a Thread or to execute, submit or schedule.
From the rule's source, thread_as_runnable.rs.
import java.util.concurrent.ExecutorService; class Workers { void start(ExecutorService executor, Runnable task) { Thread worker = new Thread(task); Thread wrapper = new Thread(worker);tx0 reports: a Thread is passed as a task executor.submit(worker);tx0 reports: a Thread is passed as a task executor.submit(task); }} 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/java:thread-as-runnable" = "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/java:thread-as-runnable] reason="..."tx0 explain tx0/java:thread-as-runnable shows the same in the terminal. Found a false positive? Report it.