Repository navigation
[java] Fix #6393: UnusedPrivateMethod FP on overloaded methods when overload resolution fails - #6947
Merged
UncleOwen merged 2 commits intoAug 14, 2026
Conversation
…n overload resolution fails What: UnusedPrivateMethod reported a false positive on one of several overloaded private methods when a call's argument is the return value of a method declared in a type that is not on the auxiliary classpath (unresolved receiver/return type), causing overload resolution to fail. Root cause: When overload resolution fails (OverloadSelectionResult#isFailed()), the selected method symbol is an arbitrary fallback, not the actually-called overload. The rule only branched into the conservative "whitelist all same-named candidates" path when the symbol was unresolved (JExecutableSymbol#isUnresolved()). A failed-but-resolved fallback therefore caused only that one overload to be marked used, flagging the remaining overload(s) as unused. Fix: Treat a failed overload selection like an unresolved call, so all same-named private method candidates are whitelisted when the receiver may be an instance of the analysed class (existing handleUnresolvedCall logic). This is consistent with the rule's existing false-positive-avoiding trade-off for unresolved calls. Testing: New test case in UnusedPrivateMethod.xml reproducing the issue (expects 0 violations). Full UnusedPrivateMethodTest: 111 tests, 0 failures, 0 errors (2 pre-existing skipped). Signed-off-by: 付典 <[email protected]>
Contributor
|
Compared to main: (comment created at 2026-08-14 11:51:01+00:00 for 05e0f8d) |
fudianchn
marked this pull request as draft
August 12, 2026 00:37
fudianchn
marked this pull request as ready for review
August 12, 2026 16:21
…oad-6393 # Conflicts: # docs/pages/release_notes.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Suppress the
UnusedPrivateMethodfalse positive on an overloaded private method when overload resolution for a call to it fails (e.g. when an argument type is not on the auxclasspath).Why
When overload resolution fails, PMD falls back to an arbitrary candidate symbol. The rule treated that fallback as the real selection and marked the other overloads as unused. Closes #6393.
Root cause
UnusedPrivateMethodRuleonly special-casedcalledMethod.isUnresolved(). On a failed overload resolution (selectionInfo.isFailed(), withcalledSymbol.isUnresolved() == false) the rule kept the fallback symbol as the chosen overload, so the real overload(s) were reported as unused.How
Treat a failed selection like an unresolved call:
This reuses the existing whitelist path —
handleUnresolvedCallalready guards cross-class receivers viareceiverMayBeInstanceOfThisClass— so no new abstraction or framework-level change is needed.Testing
UnusedPrivateMethod.xmlreproducing the issue (expected 0 problems).UnusedPrivateMethod: 'transform(Long)') and passes after the fix../mvnw -pl pmd-java -am test -Dtest=UnusedPrivateMethodTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false→Tests run: 111, Failures: 0, Errors: 0(no regression; 2 pre-existing skipped).Notes
isUnresolved()calls: when in doubt, do not report. As @oowekyala noted on the issue, the cleanest user-side fix is a correct auxclasspath; this change keeps the rule safe when that configuration is incomplete.Fixes #6393