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] Fix #6393: UnusedPrivateMethod FP on overloaded methods when overload resolution fails by fudianchn · Pull Request #6947 · pmd/pmd

Conversation

@fudianchn

@fudianchn fudianchn commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What

Suppress the UnusedPrivateMethod false 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

UnusedPrivateMethodRule only special-cased calledMethod.isUnresolved(). On a failed overload resolution (selectionInfo.isFailed(), with calledSymbol.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:

if (calledMethod.isUnresolved() || selectionInfo.isFailed()) {
    handleUnresolvedCall(ref, selectionInfo, candidates);
    return;
}

This reuses the existing whitelist path — handleUnresolvedCall already guards cross-class receivers via receiverMayBeInstanceOfThisClass — so no new abstraction or framework-level change is needed.

Testing

  • New case in UnusedPrivateMethod.xml reproducing the issue (expected 0 problems).
  • Verified it fails on the old code (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

  • This trades a possible false negative for the existing false positive, matching the rule's existing stance for 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

Sorry, something went wrong.

Uh oh!

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

All reactions
@fudianchn
[java] Fix pmd#6393: UnusedPrivateMethod FP on overloaded methods whe…
001c6ca
…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]>
@pmd-actions-helper

pmd-actions-helper Bot commented Aug 7, 2026 •
edited
Loading

Uh oh!

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

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, 16 errors and 9 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-08-14 11:51:01+00:00 for 05e0f8d)

All reactions

Sorry, something went wrong.

Uh oh!

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

@fudianchn
fudianchn marked this pull request as draft August 12, 2026 00:37
@fudianchn
fudianchn marked this pull request as ready for review August 12, 2026 16:21
@UncleOwen
Merge branch 'main' into fork/fudianchn/fix/unusedprivatemethod-overl…
05e0f8d
…oad-6393

# Conflicts:
#	docs/pages/release_notes.md
@UncleOwen UncleOwen added this to the 7.27.0 milestone Aug 14, 2026
UncleOwen
UncleOwen approved these changes Aug 14, 2026
View reviewed changes

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

Sorry, something went wrong.

Uh oh!

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

All reactions
@UncleOwen
UncleOwen merged commit 6dcf9f1 into pmd:main Aug 14, 2026
15 of 22 checks passed

Uh oh!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

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

7.27.0

Development

Successfully merging this pull request may close these issues.

[java] UnusedPrivateMethod: False positive with overloaded private methods called with values returned from methods defined in other classes

Uh oh!

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

2 participants

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