Skip to content

[java] Fix #6520: DoNotUseThreads: fix false positive on Thread.onSpinWait() #6522

Merged
adangel merged 3 commits into
pmd:mainfrom
leemeii:6520
May 7, 2026
Merged

[java] Fix #6520: DoNotUseThreads: fix false positive on Thread.onSpinWait() #6522
adangel merged 3 commits into
pmd:mainfrom
leemeii:6520

Conversation

@leemeii

@leemeii leemeii commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add regression test for Thread.onSpinWait() calls in DoNotUseThreads
  • exempt Thread.onSpinWait() static utility call from the XPath match
  • keep existing DoNotUseThreads detections unchanged for thread creation / executor usage

Root cause

DoNotUseThreads matches //ClassType references of type java.lang.Thread.
For Thread.onSpinWait(), the qualifier type Thread is represented as a ClassType, so the rule flagged it even though this call does not create or manage threads.

Verification

  • ran mvn test -Dtest=DoNotUseThreadsTest in pmd-java
  • result: 13 tests, 0 failures

Fixes #6520

@leemeii leemeii changed the title [java] DoNotUseThreads: fix false positive on Thread.onSpinWait() (#6520) [java] DoNotUseThreads: fix false positive on Thread.onSpinWait() Mar 23, 2026

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR!

Unfortunately, this PR contains the changes from your other PR (#6521). Could you please rebase this PR to only contain the relevant changes?

@adangel adangel changed the title [java] DoNotUseThreads: fix false positive on Thread.onSpinWait() [java] Fix #6520: DoNotUseThreads: fix false positive on Thread.onSpinWait() Mar 24, 2026
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@adangel adangel added needs:user-input Maintainers are waiting for feedback from author and removed needs:user-input Maintainers are waiting for feedback from author labels May 7, 2026
Comment thread pmd-java/src/main/resources/category/java/multithreading.xml
@adangel adangel added this to the 7.25.0 milestone May 7, 2026
@pmd-actions-helper

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 9 violations, 15 errors and 9 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-05-07 08:25:47+00:00 for d564f3a)

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@adangel adangel merged commit d564f3a into pmd:main May 7, 2026
13 checks passed
adangel added a commit that referenced this pull request May 7, 2026
adangel added a commit that referenced this pull request May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] DoNotUseThreads: False positive on legitimate java.lang.Thread.onSpinWait() call

2 participants