RFR (15): JDK-8242214: NullPointerException in JDK 14 javac compiling a method reference

Jan Lahoda jan.lahoda at oracle.com
Wed Jun 17 13:15:07 UTC 2020


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