Skip to content

[java] False positive for UnusedPrivateField referenced by @FieldSource#6686

Merged
UncleOwen merged 4 commits into
pmd:mainfrom
zbynek:fieldsource
May 19, 2026
Merged

[java] False positive for UnusedPrivateField referenced by @FieldSource#6686
UncleOwen merged 4 commits into
pmd:mainfrom
zbynek:fieldsource

Conversation

@zbynek

@zbynek zbynek commented May 16, 2026

Copy link
Copy Markdown
Contributor

Describe the PR

Reuses code that prevents private methods to be flagged as unused if they are referenced by @MethodSource to do the same for fields referenced by @FieldSource.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@pmd-actions-helper

pmd-actions-helper Bot commented May 16, 2026

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 0 violations, 0 errors and 0 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-18 18:47:52+00:00 for bbfa70c)

@UncleOwen UncleOwen 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.

Nice catch that this is basically already implemented!

I've left a few suggestions. Apart from those, I like it!

zbynek and others added 2 commits May 17, 2026 14:31
Co-authored-by: Sören Glimm <git@uncleowen.de>

@UncleOwen UncleOwen 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.

Remember to add the changelog entry :)

@UncleOwen UncleOwen merged commit 24056ff into pmd:main May 19, 2026
13 checks passed
@adangel adangel added this to the 7.25.0 milestone May 19, 2026
* java-bestpractices
* [#3212](https://github.com/pmd/pmd/issues/3212): \[java] Enhance UseStandardCharsets to flag some constructors of IO-related classes
* [#3777](https://github.com/pmd/pmd/issues/3777): \[java] New rule: AssertStatementInTest
* [#6606](https://github.com/pmd/pmd/issues/6606): \[java] UnusedPrivateField: False positive on JUnit Jupiter `@FieldSource`

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.

FYI:

Another way to prevent Github from notifying a user that is called "FieldSource" is using html comments, like this:

@<!-- -->FieldSource

We often have this when we reference an annotation in issue/pull request titles

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is that preferred over the backticks? I think having it rendered as code is easier to read.

(I just noticed it's also highlighting the username in the commit message, sorry about that.)

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] UnusedPrivateField: False positive on JUnit 5/6 @FieldSource

3 participants