[java] New rule: OverridingThreadRun to prefer using Runnable#6555
Conversation
b370e48 to
77479d4
Compare
|
Compared to main: (comment created at 2026-03-29 10:58:53+00:00 for 1ed4ab7) |
Co-authored-by: GitHub Copilot <[email protected]>
|
@adangel I noticed the regression report does not include this rule -- did I do something wrong here? |
Good catch. If the rule doesn't appear in the regression report, this means, there are no instances of violations detected. We only list rules, where there is a violation. That's why there are no rules with 0 violations (either for base or patch). The ruleset that is used for regression testing is simply this one: https://github.com/pmd/pmd/blob/main/.ci/files/all-regression-rules.xml - which contains java/multihreading.xml which contains OverridingThreadRun I've tested this rule now separately - it seems to be working. Now: With the help of IntelliJ I could identify a subclass of thread in java.base, that should have been found: https://github.com/openjdk/jdk/blob/da75f3c4ad5bdf25167a3ed80e51f567ab3dbd01/src/java.base/share/classes/java/lang/ref/Finalizer.java#L151 pmd/.ci/files/project-list.xml Line 183 in e7d8c88 After tinkering a bit, I found the problem: The XPath expression is not correct - it uses The better XPath is: @zbynek Can you please open a new PR to fix this? Then you should see violation in the report... However, this doesn't find anonymous classes, e.g. public class Foo {
public static void main(String[] args) {
new Thread() {
public void run() {
}
}.start();
}
}Unfortunately, |
Describe the PR
The new rule suggests using
Runnableinstead of overridingThread.run.IntelliJ covers this by AnonymousHasLambdaAlternative
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)