Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11363

Bootstrap method error for method reference used with a primitive literal

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.21, 5.0.0-alpha-8, 4.0.21
    • 3.0.22, 5.0.0-alpha-9, 4.0.22
    • None
    • None

    Description

      This code:

      import groovy.transform.CompileStatic
      import java.util.function.Supplier
      
      @CompileStatic
      Supplier<String> method() {
          5::toString
      }
      
      method().get()
      

      Fails with this error:

      java.lang.BootstrapMethodError: bootstrap method initialization exception
      	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:188)
      	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:315)
      	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:281)
      	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:271)
      	at ConsoleScript9.method(ConsoleScript9:6)
              ...
      Caused by: java.lang.invoke.LambdaConversionException: Type mismatch in captured lambda parameter 0: expecting int, found class java.lang.Object
      

      It seems like 3.0.x versions are unaffected and 4.0.13 was the first version exhibiting this behavior.

      My initial expectation is that the wrapper type/boxed version should be used.

      See also:
      https://stackoverflow.com/questions/78369048/groovy3-how-to-get-java-lambdas-instead-of-closures

      Attachments

        Activity

          People

            emilles Eric Milles
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: