Repository navigation
[java] Fix #7151: Apply the comb rule to unqualified method calls - #7161
Merged
Merged
Conversation
The method scope of a class merged the methods of the enclosing classes and dropped only the override-equivalent ones. JLS 15.12.1 searches the innermost enclosing class or interface that has a member method with the name of the call. The method scope now shadows the enclosing methods by name, as the scopes of fields and types do, and the custom merger is removed. Supertype methods that are not inherited no longer count as members of the subclass for this lookup. That covers private methods and package-private methods whose inheritance stops at a subclass in another package.
Contributor
|
Compared to main: (comment created at 2026-10-07 15:42:12+00:00 for 7a1591c) |
3 of 4 tasks
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 an unqualified call, PMD merged the methods of the enclosing classes into the scope of a nested class and dropped only the override-equivalent ones. With
Inner.m(long)andComb.m(Object), both reached overload resolution andm(Object)won. JLS 15.12.1 searches the innermost enclosing class or interface that has a member method with that name. The method scope of the class now shadows the enclosing methods by name, with the same shadow barrier the scopes of fields and types use. The custom merger is gone. Two details follow from the rule. Supertype methods that are not inherited are not members of the subclass (JLS 8.4.8), so they must not stop the search. Accessibility alone does not decide that: private methods are never inherited, and a package-private method is not inherited by a subclass in another package, so a class in the original package that extends that subclass does not have it either. javac selects the enclosing method in that case. The old merger also dropped the instance methods of an enclosing class from the scope of a static nested class that has no method of that name. Those methods are in scope under JLS 6.3. If overload resolution selects one for an unqualified call, JLS 15.12.3 then checks whether the compile-time declaration is appropriate.New cases in
MemberInheritanceTest:javasymbols.testdataThree existing expectations in that file encoded the old merging and now follow the rule.
Ran
./mvnw -B -ntp -pl pmd-java verifywith Java 21.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)