RFR (15): JDK-8242214: NullPointerException in JDK 14 javac compiling a method reference
Vicente Romero
vicente.romero at oracle.com
Wed Jun 17 16:15:47 UTC 2020
Hi Jan,
Out of curiosity, as this is a regression, do we know what was the
change that introduced the issue and what was the related code like
before the change that provoked the regression?
Thanks,
Vicente
On 6/17/20 9:15 AM, Jan Lahoda wrote:
> Hi,
>
> There is a tricky issue related to unbound instance method references
> to a protected method in a superclass.
>
> Consider:
> ---base/Base.java:
> package base;
>
> public class Base {
> protected void test() {}
> }
> ---impl/Impl.java:
> package impl;
>
> import base.Base;
> import java.util.function.Consumer;
>
> public class Impl extends Base {
> Consumer<Impl> consumer() {
> return Impl::test;
> }
> }
> ---
>
> Since JDK-8234729, javac tries to expand the method reference to a
> lambda:
> (/*synthetic*/ Object rec$)->((Base)rec$).test()
>
> But this is not quite right (and crashes javac) - Impl cannot invoke
> test on "Base":
> ((Base) rec$).test();
>
> it needs to invoke (if I understand JLS 6.6.2.1. correctly) test on
> "Impl":
> ((Impl) rec$).test();
>
> So, the expanded lambda for the method reference should be:
> (/*synthetic*/ Object rec$)->((Impl)rec$).test()
>
> Which is what the proposed patch is trying to do.
>
> Webrev:
> http://cr.openjdk.java.net/~jlahoda/8242214/webrev.00/
>
> JBS:
> https://bugs.openjdk.java.net/browse/JDK-8242214
>
> How does this look?
>
> Thanks,
> Jan
More information about the compiler-dev
mailing list