Reported on https://mail.openjdk.java.net/pipermail/jdk-dev/2021-October/006099.html
This is to follow up the behavorial change on LambdaMetaFactory::metafactory when the implementation is REF_invokeSpecial method handle on a public/protected method in the target class. This won't happen for classes compiled from javac since REF_invokeSpecial method handle is generated when the method is a private method whereas REF_invokeVirtual method handle would be generated on a public/protected.
To reproduce:
1. compile it with java 8
2. modify the access of testPrivate from private to public in .class file (do not modify any invokespecial and ref_invokespecial).
3. Java 14 without JEP 371, the method reference `this::testPrivate` with REF_invokeSpecial kind will be resolved to ExampleClass::testPrivate on a receiver of type ExampleClass$SubClass. With JEP 371 change, the method reference `test::testPrivate` with REF_invokeSpecial kind will be resolved to ExampleClass$Subclass::testPrivate instead.
import java.util.function.Supplier;
public class ExampleClass {
public static void main(String[] args) {
System.out.println(new SubClass().test());
System.out.println(new SubClass().testWithLMF());
}
public String test() {
return this.testPrivate();
}
public String testWithLMF() {
Supplier<String> supplier = this::testPrivate;
return supplier.get();
}
private String testPrivate() {
return "123";
}
public static class SubClass extends ExampleClass {
public String testPrivate() {
return "456";
}
}
}
Java 14:
$ java ExampleClass
123
123
Java 15:
$ java ExampleClass
123
456