Repository navigation
Conversation
…d calls For a call like Foo.m(value), MethodInvocMirror asked TypeOps.getMethodsOf for static methods only. JLS 15.12.2.1 searches all member methods and 15.12.3 checks the static modifier after the most specific one is chosen, so javac selects an instance method there and reports an error. The candidates of a qualified call are now the accessible methods that are members of the qualifier type. Accessibility alone admitted methods that are not members, such as a private method of a superclass in the same nest or a protected method of Object for an interface type. The member check of the method scope of a class moves to JavaResolvers.isMemberMethod, which both use. An intersection has the members of its induced class or interface (JLS 4.9), which inherits neither private methods nor static interface methods of its components. The induced interface, used when the class component is Object, has only public members. For a type name qualifier, a protected method of another package is checked against JLS 6.6.2 instead of the accessibility filter, which only looks at the innermost enclosing class and not at the qualifier. Such a method is accessible in the body of a subclass S of its declaring class, including the classes nested in S. An instance method also needs the type to be S or a subclass of S.
Contributor
|
Compared to main: (comment created at 2026-11-14 03:01:37+00:00 for f4fb2d9) |
This was referenced Nov 11, 2026
Member
So does this method still have a use? If it's not meant to be kept, it should be deprecated. |
Since the fix of pmd#7152, PMD does not call this method.
Contributor
Author
|
No, nothing in PMD calls it after this PR. I've deprecated it in 16906bc and added it to the release notes. |
This branch has not been deployed
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.
Describe the PR
For a call like
Foo.m(value),MethodInvocMirroraskedTypeOps.getMethodsOffor static methods only. JLS 15.12.2.1 searches all member methods, and 15.12.3 checks the static modifier after the most specific method is chosen. Withstatic m(int)andm(Object), javac selectsm(Object)for anIntegerargument and reports that it is not static. PMD resolved the call tom(int). With an interface as qualifier, the abstract and default methods of the interface were skipped the same way.The candidates of a qualified call are now the accessible methods that are members of the qualifier type, for a type name and for an expression. For an expression,
mainchecked accessibility only, which also admits methods that are not members. These calls compile, andmainresolved them differently from javac:child.m(value), whereChilddeclaresstatic m(int)and its superclass in the same nest has a privatem(Object): javac resolves the call toChild.m(int),maintoParent.m(Object)U extends TwithT extends Child, or throughT extends Child & Markerj.clone(), where the interfaceJdeclaresObject clone(): javac resolves the call toJ.clone(),maintoObject.clone()t.clone()with<T extends I & J>, whereIdeclaresvoid clone(Object...): javac resolves the call toI.clone(Object...),maintoObject.clone()JavaResolvers.isMemberMethoddecides membership. It takes the checks of the method scope of a class for private and package-private methods of supertypes and for static interface methods, and adds that an interface has only the public methods ofObject(JLS 9.2). The method scope now calls it. Onmain,Object.clone()in the method scope of an interface also hides the methods namedcloneof an enclosing class: in an interface nested in a class that declaresstatic void clone(int),clone(1)is not resolved. javac calls the method of the enclosing class, and PMD now does too.An intersection has the members of its induced class or interface (JLS 4.9), which inherits neither private methods nor static interface methods, even those declared by a component. If the class component is
Object, the induced type is an interface and has only the public methods ofObject. For<T extends I & J>, javac findsObject.clone()and reports thatt.clone()has protected access inObject. WhenIdeclaresclone(Object...), javac resolvest.clone()to that method, and PMD now does too. With a single bound<T extends C>, javac selects a private method ofCand reports that it has private access, and PMD keeps that choice.For a type name qualifier, a protected method of another package is checked against JLS 6.6.2 instead of the accessibility check of PMD, which looks only at the innermost enclosing class and not at the qualifier type (#7147). Such a method is accessible in the body of a subclass
Sof its declaring class, including the classes nested inS, and an instance method also needs the type to beSor a subclass ofS(6.6.2.1). Without the qualifier check,Base.m(value)in a subclass in another package would select a protectedm(Object)instead ofstatic m(int), which javac calls andmainselects.Sub.m(value)in that subclass selectsm(Object), as javac does before it reports that the method is not static. In a class nested in that subclass,Base.s(value)with a protectedstatic s(Object)and a publicstatic s(int)compiles and javac callss(Object).mainresolves it tos(int).When an instance method is chosen for a type name qualifier, PMD keeps it as the compile-time declaration. Unqualified calls in a static context behave the same way: the method scope contains the instance methods and the static context is not checked after the choice.
MethodInvocMirrorno longer callsTypeOps.getMethodsOf, and nothing else in PMD does, so it is deprecated.New cases in
OverloadResolutionTest, each checked against javac 21:Objectfor an interface and for an intersection of interfaces, qualified and in an interface body, and an interface nested in a class with aclonemethodjavasymbols.testdataFor an expression qualifier, the qualifier type of a protected method is still not checked. With
<T extends K & J>, where the classKdeclaresclone(Object...), PMD resolvest.clone()toObject.clone()onmainand with this PR, while javac callsK.clone(Object...). That is #7147.Ran
./mvnw -B -ntp -pl pmd-java verifywith Java 21. Eighteen of the 25 new tests fail onmain. The other seven cover cases thatmainresolves as javac does.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)