GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — [java] Fix #7340: UnusedPrivateMethod should not treat arbitrary annotation strings as method uses by markjoin123 · Pull Request #7355 · pmd/pmd Conversation
Contributor
Describe the PR
String constants are now collected only from annotations that name methods:
Related issues
Testing
Ready?
This change was made with AI assistance and reviewed.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…nnotation strings as method uses UnusedPrivateMethod reused the annotation scan that treats every string constant as a referenced member. A value such as @SuppressWarnings("helper") therefore hid an unused no-arg private method of that name. Collect those strings only from annotations that name methods: JUnit @MethodSource and Lombok @ObtainVia. UnusedPrivateField still considers every annotation string. Fixes pmd#7340
|
There was an error while loading. Please reload this page.
|
Compared to main: (comment created at 2026-11-19 00:06:35+00:00 for 529c364) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
There are more frameworks that reference methods by passing their names to annotations: TestNG, Mapstruct, MyBatis. I'm sure there's more. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…s as uses UnusedPrivateMethod now reads only the attributes that name methods on those annotations. Other annotation strings, including descriptions, SQL, and property names, still do not hide unused private methods. Co-authored-by: markxu <[email protected]>
|
Thanks for the review. I've expanded the allowlist so
Other strings on those same annotations (SQL, descriptions, property names, Java expressions) are still not treated as uses. The rule comment notes that this is the known set and can be extended if more frameworks show up. I added tests for these cases: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…lected ReturnEmptyCollectionRatherThanNull flagged attributesFor for returning null. An empty set now means that annotation contributes no names, while an explicit empty allowlist entry still reads every string member.
|
If we fix this, we should fix this for both UnusedPrivateMethod and UnusedPrivateField. But I don't think we should. This PR introduces unnecessary complexity for what should be a fairly simple rule. I don't like that it adds yet another list of annotations that we need to maintain. The old code made an assumption: If an annotation-parameter is exactly the name of a method, that method is used somehow. That assumption is reasonable. We shouldn't abandon it, when all we have is one (contrived?) example. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[java] UnusedPrivateMethod: any annotation string equal to the method name counts as a use
There was an error while loading. Please reload this page.