lambda reference to inner class in base class causes LambdaConversionException

Robert Field robert.field at oracle.com
Thu Jun 19 18:28:05 UTC 2014


Hi Remi,

I have a fix in-process to fix this issue -- currently awaiting review.  
It will go into JDK9, since it is too extensive to go into an update 
release.  I have confirmed that it fixes this issue too and will mark as 
a duplicate.

Thanks,
Robert

On 06/19/14 05:53, Remi Forax wrote:
> I've just take a look to bug 8047341 [1] and I think it's a javac bug 
> and not a bug in the lambda meta-factory,
> moreover, Eclipse generates a code which doesn't throw an exception at 
> runtime.
>
> In list.stream().forEach(TestString::new), TestString::new reference 
> the constructor of TestString
> which is an inner class (non static) of FooBase, so the constructor 
> takes a hidden FooBase parameter
> so the method reference should refer to TestString(FooBase, String).
>
> The code generated by javac is:
>   14: aload_0
>   15: invokedynamic #5,  0              // InvokeDynamic 
> #0:accept:(LFoo;)Ljava/util/function/Consumer;
>   20: invokeinterface #6,  2            // InterfaceMethod 
> java/util/stream/Stream.forEach:(Ljava/util/function/Consumer;)V
>
> while Eclipse ecj generates:
>   14: aload_0
>   15: invokedynamic #27,  0             // InvokeDynamic 
> #0:accept:(LFooBase;)Ljava/util/function/Consumer;
>   20: invokeinterface #28,  2           // InterfaceMethod 
> java/util/stream/Stream.forEach:(Ljava/util/function/Consumer;)V
>
> as you can see, javac generate an invokedynamic call with a Foo 
> instead of a FooBase which I think is the correct behavior.
>
> So for me, it's a bug in javac, not in the meta-factory.
>
> cheers,
> Rémi
>
> [1] https://bugs.openjdk.java.net/browse/JDK-8047341
>
>



More information about the compiler-dev mailing list