GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Update UnusedPrivateFieldRule - ignore any annotations by LynnBroe · Pull Request #4100 · pmd/pmd

Conversation

@LynnBroe

@LynnBroe LynnBroe commented Aug 24, 2022 •
edited by adangel
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Describe the PR

I improve the rule UnusedPrivatefield and make the annotation @spybean can be detected

Related issues

  • Fixes [java] UnusedPrivateField - false positive with Lombok @ToString.Include #4033
  • Fixes [java] UnusedPrivateField - false positive with Spring @SpyBean #4037

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@LynnBroe
Update UnusedPrivateFieldRule.java
738c19b
revise SpyBean about unusedprivatefield
@LynnBroe LynnBroe changed the title Update UnusedPrivateFieldRule.java: add a new rule to detect @SpyBean Update UnusedPrivateFieldRule.java: I improve the rule UnusedPrivatefield and make the annotation @SpyBean can be detected Aug 24, 2022
@adangel
adangel self-requested a review August 24, 2022 16:02
@ghost

ghost commented Aug 29, 2022 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
1 Message
📖 Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 55 violations, 2 errors and 6 configuration errors.
Full report
✅ Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 55 violations, 2 errors and 6 configuration errors.
Full report
✅ Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 2 errors and 6 configuration errors.
Full report
✅ Compared to master:
This changeset changes 0 violations,
introduces 15 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adangel
adangel requested changes Aug 29, 2022
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for your PR!

Please add a new test case to prove that #4037 is indeed fixed.

However, I think it's time to test another strategy for fixing these issues: Please try out what happens, if this rule just doesn't report any private fields, that has any annotations.
Because otherwise, we will keep adding one annotation after another, until every java framework is represented in this rule.
If this new strategy works and doesn't create too many false positives, then we would also have a fix for #4033 (and possible other issues).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

oowekyala reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@adangel adangel changed the title Update UnusedPrivateFieldRule.java: I improve the rule UnusedPrivatefield and make the annotation @SpyBean can be detected [java] Update UnusedPrivateFieldRule.java: I improve the rule UnusedPrivatefield and make the annotation @SpyBean can be detected Aug 29, 2022
LynnBroe and others added 2 commits September 5, 2022 15:28
@LynnBroe
Merge branch 'pmd:master' into master
bd0a2e3
@LynnBroe
Update UnusedPrivateField.xml
ba0f2a2
@LynnBroe

LynnBroe commented Sep 5, 2022

Copy link
Copy Markdown
Contributor Author

Hi, adangel, I have added the test case, could you please help check it? Besides, I think it is inappropriate to dismiss all fields with annotations because many annotations may do not affect the current rule under checking. Fixing these issues is very easy, but dismissing them could lead to many false negatives. Thanks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel changed the title [java] Update UnusedPrivateFieldRule.java: I improve the rule UnusedPrivatefield and make the annotation @SpyBean can be detected [java] Update UnusedPrivateFieldRule - ignore annotation @SpyBean Sep 29, 2022
adangel added 4 commits September 29, 2022 18:31
@adangel
Merge branch 'master' into pr-4100
a66cffa
@adangel
[java] UnusedPrivateField - ignore any annotations
306db99
Deprecate "ignoreAnnotations" property
@adangel
[java] UnusedPrivateFieldRule - improve rule doc
e712b89
@adangel
[java] UnusedPrivateFieldRule - remove ignoredAnnotations from rule t…
1cc0fbb
…ests
@adangel

adangel commented Sep 30, 2022

Copy link
Copy Markdown
Member

Thanks for the updated test case.

Besides, I think it is inappropriate to dismiss all fields with annotations because many annotations may do not affect the current rule under checking. Fixing these issues is very easy, but dismissing them could lead to many false negatives. Thanks

That's why I wanted to try this out to see the impact. I just did it - see the last regression tester report. It's not too bad IMHO.

Static code analysis always needs to balance false positives and false negatives. In that case - the rule is in category "best practices" - there is no big harm in having some false negatives (no program will crash because of an unused private field). Therefore I believe it is more important to reduce false positives than to avoid any false negatives. If the rule is too noisy it may lead to being ignored or disabled and maybe even removed from the ruleset entirely. In the end, the rule might not be used at all anymore.

I decided to deprecate the property "ignoreAnnotations". If there are good examples for false negatives, we might think of adding a new property to change the behavior, to deal with some annotations in a special way (e.g. "reportForAnnotations") or have a boolean flag (e.g. "reportRegardlessOfAnnotations"=true) which could be enabled if needed and would report all unused private fields whether annotated or not.

Having a more general solution also has the positive side effect, that #4033 is also fixed now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added this to the 6.50.0 milestone Sep 30, 2022
@adangel
[java] Fix rule tests with dysfunctional rule configurations
4fc12f0
@adangel adangel changed the title [java] Update UnusedPrivateFieldRule - ignore annotation @SpyBean [java] Update UnusedPrivateFieldRule - ignore any annotations Sep 30, 2022
@adangel
Fix release notes
16bb510
adangel
adangel approved these changes Sep 30, 2022
View reviewed changes
@adangel
adangel merged commit 16bb510 into pmd:master Sep 30, 2022
adangel added a commit to adangel/pmd that referenced this pull request Sep 30, 2022
@adangel
[doc] Update release notes (pmd#4100, pmd#4033, pmd#4037)
2105bde
adangel added a commit to adangel/pmd that referenced this pull request Sep 30, 2022
@adangel
Merge pull request pmd#4100 from LynnBroe:master
9441091
[java] Update UnusedPrivateFieldRule - ignore any annotations pmd#4100
@adangel adangel mentioned this pull request Oct 18, 2022
[java] UnusedPrivateField doesn't find annotated unused private fields anymore #4166
Closed
@adangel adangel mentioned this pull request Oct 27, 2022
[java] ImmutableField - deprecate property ignoredAnnotations #4175
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

6.50.0

Development

Successfully merging this pull request may close these issues.

[java] UnusedPrivateField - false positive with Spring @SpyBean [java] UnusedPrivateField - false positive with Lombok @ToString.Include

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@LynnBroe @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.