GeezerVison is showing github.com — [java] Update UnusedPrivateFieldRule - ignore any annotations by LynnBroe · Pull Request #4100 · pmd/pmd
Conversation
LynnBroe
commented
Aug 24, 2022
•
edited by adangel
Loading
Uh oh!
There was an error while loading. Please reload this page.
Describe the PR
I improve the rule UnusedPrivatefield and make the annotation @spybean can be detected
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)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
revise SpyBean about unusedprivatefield
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
ghost
commented
Aug 29, 2022
•
edited by ghost
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
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
|
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
Deprecate "ignoreAnnotations" property
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
adangel
changed the title
[java] Update UnusedPrivateFieldRule - ignore annotation @SpyBean
[java] Update UnusedPrivateFieldRule - ignore any annotations
Sep 30, 2022
adangel
added a commit
to adangel/pmd
that referenced
this pull request
Sep 30, 2022
[java] Update UnusedPrivateFieldRule - ignore any annotations pmd#4100
Reviewers
adangel
adangel approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
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.
|