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] Unqualified method call resolves to an enclosing class method that the inner class hides · Issue #7151 · pmd/pmd

[java] Unqualified method call resolves to an enclosing class method that the inner class hides #7151

New issue
Copy link
New issue
Copy link
Closed
#7161
Closed
[java] Unqualified method call resolves to an enclosing class method that the inner class hides#7151
#7161
Copy link
Labels
in:symbol-tableAffects the symbol table code
Milestone
7.29.0

Description

@saryn17
saryn17
opened on Oct 6, 2026
Issue body actions

Affects PMD Version: 7.28.0 (also 7.29.0-SNAPSHOT)

Description:

In the sample, Inner declares m(long) and the enclosing class Comb declares m(Object). For m(value) with an Integer value, javac searches only the innermost class that has a method named m (JLS 15.12.1), so Inner.m(long) is the only candidate and the call compiles to m:(J)V. PMD resolves the call to Comb.m(Object).

The unqualified lookup merges the methods of the enclosing class into the scope of the inner class and shadows only override-equivalent ones:

pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/JavaResolvers.java

Lines 291 to 329 in 5c9271c

/**
* Merges two method scopes, the otherResult is the one of an enclosing class,
* the inner result is the one inherited from supertypes (which take precedence
* in case of override equivalence).
*
* <p>Non-static methods of the outer result are excluded if the inner scope is static.
*/
private static List<JMethodSig> methodMerger(boolean inStaticType, List<JMethodSig> myResult, List<JMethodSig> otherResult) {
if (otherResult.isEmpty()) {
return myResult;
} // don't check myResult for emptiness, we might need to remove static methods
// For both the input lists, their elements are pairwise non-equivalent.
// If any element of myResult is override-equivalent to
// another in otherResult, then we must exclude the otherResult
BitSet isShadowed = new BitSet(otherResult.size());
for (JMethodSig m1 : myResult) {
int i = 0;
for (JMethodSig m2 : otherResult) {
boolean isAlreadyShadowed = isShadowed.get(i);
if (!isAlreadyShadowed && TypeOps.areOverrideEquivalent(m1, m2)
|| inStaticType && !m2.isStatic()) {
isShadowed.set(i); // we'll remove it later
}
i++;
}
}
if (isShadowed.isEmpty()) {
return CollectionUtil.concatView(myResult, otherResult);
} else {
List<JMethodSig> result = new ArrayList<>(myResult.size() + otherResult.size() - 1);
result.addAll(myResult);
copyIntoWithMask(otherResult, isShadowed, result);
return Collections.unmodifiableList(result);
}
}

The merger is installed in SymTableFactory (lines 410-412). Both methods then reach the overload resolution, m(Object) is applicable by strict invocation and wins.

Found while working on #7136.

Code Sample demonstrating the issue:

class Comb {
    void m(Object o) { }

    class Inner {
        void m(long x) { }

        void t(Integer value) {
            m(value);
        }
    }
}

Steps to reproduce:

  1. javac Comb.java, also with --release 8, then javap -c -p 'Comb$Inner': the call is m:(J)V.
  2. Run PMD on Comb.java with the XPath rule //MethodCall[pmd-java:matchesSig("Comb#m(java.lang.Object)")]. It reports line 8.

Running PMD through: Other (PmdAnalysis API)

Activity

  1. saryn17
    added a commit that references this issue on Oct 6, 2026

    [java] UnnecessaryBoxing: rerun the overload resolution without the u…

    15327e0
  2. oowekyala
    added this to the 7.29.0 milestone on Oct 23, 2026
  3. adangel
    closed this as completedin #7161on Oct 23, 2026
  4. adangel
    added
    in:type-resolutionAffects the type resolution code
    in:symbol-tableAffects the symbol table code
    and removed
    in:type-resolutionAffects the type resolution code
    on Oct 23, 2026
  5. adangel
    added 2 commits that reference this issue on Oct 23, 2026

    [java] Fix pmd#7151: Apply the comb rule to unqualified method calls (p…

    This issue will close once commit b93f2a8 is merged into the 'main' branch.
    b93f2a8

    Enable test case after pmd#7151 has been fixed

    This issue will close once commit 1d042fa is merged into the 'main' branch.
    1d042fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in:symbol-tableAffects the symbol table code

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.29.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.