A subclass of Thread neither overrides run() nor passes a task to its constructor

tx0/java:thread-without-taskrecommendedwarningbug, concurrency

What it finds

A class that extends Thread but does not override run(), and passes no task to the Thread constructor, starts threads that do nothing: Thread.run() runs only a task given to the constructor.

From the rule's source, thread_without_task.rs.

Example from the rule's tests
class Idle extends Thread {tx0 reports: Idle extends Thread but gives it nothing to run  Idle() {    setDaemon(true);  }} class Busy extends Thread {  @Override  public void run() {}} class Wrapped extends Thread {  Wrapped(Runnable task) {    super(task);  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/java:thread-without-task" = "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-without-task] reason="..."

tx0 explain tx0/java:thread-without-task shows the same in the terminal. Found a false positive? Report it.