RFR: 8318160: javac does not reject private method reference with type-variable receiver
Vicente Romero
vromero at openjdk.org
Tue Oct 17 00:32:52 UTC 2023
On Tue, 17 Oct 2023 00:19:56 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> Please review this PR which is fixing a long standing regression in javac. Basically javac is accepting code like:
>
>
> import java.util.function.*;
>
> class Test {
> private String asString() {
> return "bar";
> }
>
> static <T extends Test> Function<T, String> foo() {
> return T::asString;
> }
> }
>
>
> this code should be rejected on the grounds that ::asString is a private method in class Test and no subclass of it should have access to this method. This regression was introduced in JDK9 so it could be that there is code depending on this bug.
>
> TIA
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java line 3555:
> 3553: MethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site,
> 3554: List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) {
> 3555: super(referenceTree, name, types.skipTypeVars(site, true, true), argtypes, typeargtypes, maxPhase);
I believe the right thing here should be to skip captured type variables but not "non-captured" type variables
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16210#discussion_r1361382803
More information about the compiler-dev
mailing list