JDK-8047341 : lambda reference to inner class in base class causes LambdaConversionException
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u5,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-06-18
  • Updated: 2015-06-01
  • Resolved: 2014-06-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b22Resolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux ws-win-gpb 2.6.34.8-0.2-desktop #1 SMP PREEMPT 2011-04-06 18:11:26 +0200 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :

define an inner class in a base class

instantiate the inner class in a derived class
with lambda "InnerClass::new" and an exception occurs

exception is
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch in captured lambda parameter 0: expecting class Foo, found class FooBase



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Foo.java
java Foo


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
no exception
ACTUAL -
Exception:
Exception in thread "main" java.lang.BootstrapMethodError: call site initialization exception
	at java.lang.invoke.CallSite.makeSite(CallSite.java:328)
	at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:296)
	at Foo.run(Foo.java:20)
	at Foo.main(Foo.java:13)
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch in captured lambda parameter 0: expecting class Foo, found class FooBase
	at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:256)
	at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
	at java.lang.invoke.CallSite.makeSite(CallSite.java:289)
	... 3 more



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.List;
import java.util.ArrayList;
class FooBase {
  class TestString {
    String str;
    TestString(String strin) {
      str = strin;
    }
  }
}
class Foo extends FooBase {
  public static void main(String[] args) {
    new Foo().run();
  }  
  Foo() {
    super();
  }
  void run() {
    List<String> list = new ArrayList<>();
    list.stream().forEach(TestString::new);
  }
}

---------- END SOURCE ----------


Comments
Test(s) was added with this push --- URL: http://hg.openjdk.java.net/jdk9/dev/langtools/rev/2b6b96ed3878 User: rfield Date: 2014-06-25 18:22:47 +0000
27-06-2014