RFR (15): JDK-8242214: NullPointerException in JDK 14 javac compiling a method reference
Vicente Romero
vicente.romero at oracle.com
Thu Jun 18 13:13:36 UTC 2020
thanks for the research, the patch looks good,
Vicente
On 6/17/20 5:06 PM, Jan Lahoda wrote:
> The patch that provoked this was JDK-8234729:
> https://bugs.openjdk.java.net/browse/JDK-8234729
>
> Before that, a method reference like this would not be unrolled into a
> lambda, and all would work. But now more method references are
> unrolled into lambdas, which is triggering the bug.
>
> Jan
>
> On 17. 06. 20 18:15, Vicente Romero wrote:
>> 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