Skip to content

THREAD_RUN_DIRECT_CALL

Summary

  • Rule ID: THREAD_RUN_DIRECT_CALL
  • Name: Thread.run direct call
  • Problem: Calling Thread.run() directly runs on the current thread and usually indicates a missed start() call.

What This Rule Reports

This rule reports direct invocations of: - java/lang/Thread.run()V

Examples (reported)

package com.example;
public class ClassA {
    public void methodX() {
        Thread varOne = new Thread(() -> {});
        varOne.run();
    }
}

What This Rule Does Not Report

  • Calls to Thread.start().
  • super.run() calls inside an overridden run()V method.
  • Calls that appear only in classpath/dependency classes outside the analysis target.

Examples (not reported)

package com.example;
public class ClassB {
    public void methodY() {
        Thread varOne = new Thread(() -> {});
        varOne.start();
    }
}
package com.example;
public class ClassC extends Thread {
    @Override
    public void run() {
        super.run();
    }
}

If asynchronous execution is intended, replace direct run() calls with start().

Message Shape

Findings are reported as Avoid direct Thread.run() in <class>.<method><descriptor>; call start() for asynchronous execution.