Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8047341

lambda reference to inner class in base class causes LambdaConversionException

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u5, 9
    • Fix Version/s: 9
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b22
    • CPU:
      x86_64
    • OS:
      linux
    • Verification:
      Verified

      Backports

        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 ----------

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                rfield Robert Field
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: