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

bootstrap method initialization exception raised when lambda parameter type is wrong

    XMLWordPrintableJSON

Details

    Description

      The following code will raise BME

      import java.util.stream.*
      
      @groovy.transform.CompileStatic
      def x() {
          IntStream.range(0, 2).forEach((Integer i) -> { assert 0 <= i && i < 2})
          // IntStream.range(0, 2).forEach(i -> { assert 0 <= i && i < 2}) // raise BME too
      }
      
      x()
      

      but the following code works well:

      import java.util.stream.*
      
      @groovy.transform.CompileStatic
      def x() {
          IntStream.range(0, 2).forEach((int i) -> { assert 0 <= i && i < 2})
      }
      
      x()
      

      BME stacktrace:

      java.lang.BootstrapMethodError: bootstrap method initialization exception
      
      	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:194)
      
      	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:315)
      
      	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:271)
      
      	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:261)
      
      	at ConsoleScript15.x(ConsoleScript15:5)
      
      	at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
      
      	at ConsoleScript15.run(ConsoleScript15:8)
      
      	at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:254)
      
      	at groovy.lang.GroovyShell.run(GroovyShell.java:360)
      
      	at groovy.lang.GroovyShell.run(GroovyShell.java:339)
      
      	at groovy.lang.GroovyShell.run(GroovyShell.java:166)
      
      	at groovy.lang.GroovyShell$run$0.call(Unknown Source)
      
      	at groovy.console.ui.Console$_runScriptImpl_closure22.doCall(Console.groovy:1302)
      
      	at groovy.console.ui.Console$_runScriptImpl_closure22.doCall(Console.groovy)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
      
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      
      	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
      
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
      
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263)
      
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
      
      	at groovy.lang.Closure.call(Closure.java:412)
      
      	at groovy.lang.Closure.call(Closure.java:406)
      
      	at groovy.lang.Closure.run(Closure.java:493)
      
      	at java.base/java.lang.Thread.run(Thread.java:832)
      
      Caused by: java.lang.invoke.LambdaConversionException: Type mismatch for instantiated parameter 0: class java.lang.Integer is not a subtype of int
      
      	at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.checkDescriptor(AbstractValidatingLambdaMetafactory.java:322)
      
      	at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:308)
      
      	at java.base/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:327)
      
      	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:127)
      
      	... 25 more
      
      

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            daniel_sun Daniel Sun
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m