lambda reference to inner class in base class causes LambdaConversionException

Remi Forax forax at univ-mlv.fr
Thu Jun 19 12:53:09 UTC 2014


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 core-libs-dev mailing list