[jira] [Updated] (GROOVY-8499) Glitch with native lambda support when supplied with incorrect arity lambda

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (GROOVY-8499) Glitch with native lambda support when supplied with incorrect arity lambda

JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/GROOVY-8499?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King updated GROOVY-8499:
------------------------------
    Description:
The following code works:
{code}
import groovy.transform.*

@CompileStatic
def method() {
  ['ab'.chars, '12'.chars].combinations().stream().collect((x, y) -> "$x$y").forEach{ println it }
}

method()
{code}
but if I make an error like this:
{code}
import groovy.transform.*

@CompileStatic
def method() {
  ['ab'.chars, '12'.chars].combinations().stream().map((x, y) -> "$x$y").forEach{ println it }
}

method()
{code}
I get the following error:
{noformat}
Exception thrown
java.lang.BootstrapMethodError: call site initialization exception
        at java.lang.invoke.CallSite.makeSite(CallSite.java:341)
        at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:307)
        at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:297)
        at ConsoleScript33.method(ConsoleScript33:5)
        at ConsoleScript33.run(ConsoleScript33:9)
        at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:265)
        at groovy.lang.GroovyShell.run(GroovyShell.java:378)
        at groovy.lang.GroovyShell.run(GroovyShell.java:357)
        at groovy.lang.GroovyShell.run(GroovyShell.java:173)
        at groovy.lang.GroovyShell$run$0.call(Unknown Source)
        at groovy.ui.Console$_runScriptImpl_closure18.doCall(Console.groovy:1118)
        at groovy.ui.Console$_runScriptImpl_closure18.doCall(Console.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:103)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1037)
        at groovy.lang.Closure.call(Closure.java:419)
        at groovy.lang.Closure.call(Closure.java:413)
        at groovy.lang.Closure.run(Closure.java:500)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.invoke.LambdaConversionException: Incorrect number of parameters for instance method invokeVirtual ConsoleScript33$_method_lambda1.doCall:(ConsoleScript33,Object,Object)Object; 2 captured parameters, 1 functional interface method parameters, 3 implementation parameters
        at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:193)
        at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
        at java.lang.invoke.CallSite.makeSite(CallSite.java:302)
        ... 23 more
{noformat}
We should produce a sensible error message in this case.

  was:
The following code works:
{code}
import groovy.transform.*

@CompileStatic
def method() {
  ['ab'.chars, '12'.chars].combinations().collect{x, y -> "$x$y"}.each{ println it }
}

method()
{code}
but the lambda equivalent doesn't:
{code}
import groovy.transform.*

@CompileStatic
def method() {
  ['ab'.chars, '12'.chars].combinations().stream().map((x, y) -> "$x$y").forEach{ println it }
}

method()
{code}
giving the following error:
{noformat}
Exception thrown
java.lang.BootstrapMethodError: call site initialization exception
        at java.lang.invoke.CallSite.makeSite(CallSite.java:341)
        at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:307)
        at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:297)
        at ConsoleScript33.method(ConsoleScript33:5)
        at ConsoleScript33.run(ConsoleScript33:9)
        at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:265)
        at groovy.lang.GroovyShell.run(GroovyShell.java:378)
        at groovy.lang.GroovyShell.run(GroovyShell.java:357)
        at groovy.lang.GroovyShell.run(GroovyShell.java:173)
        at groovy.lang.GroovyShell$run$0.call(Unknown Source)
        at groovy.ui.Console$_runScriptImpl_closure18.doCall(Console.groovy:1118)
        at groovy.ui.Console$_runScriptImpl_closure18.doCall(Console.groovy)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:103)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1037)
        at groovy.lang.Closure.call(Closure.java:419)
        at groovy.lang.Closure.call(Closure.java:413)
        at groovy.lang.Closure.run(Closure.java:500)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.invoke.LambdaConversionException: Incorrect number of parameters for instance method invokeVirtual ConsoleScript33$_method_lambda1.doCall:(ConsoleScript33,Object,Object)Object; 2 captured parameters, 1 functional interface method parameters, 3 implementation parameters
        at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:193)
        at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
        at java.lang.invoke.CallSite.makeSite(CallSite.java:302)
        ... 23 more
{noformat}



> Glitch with native lambda support when supplied with incorrect arity lambda
> ---------------------------------------------------------------------------
>
>                 Key: GROOVY-8499
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8499
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.x
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>
> The following code works:
> {code}
> import groovy.transform.*
> @CompileStatic
> def method() {
>   ['ab'.chars, '12'.chars].combinations().stream().collect((x, y) -> "$x$y").forEach{ println it }
> }
> method()
> {code}
> but if I make an error like this:
> {code}
> import groovy.transform.*
> @CompileStatic
> def method() {
>   ['ab'.chars, '12'.chars].combinations().stream().map((x, y) -> "$x$y").forEach{ println it }
> }
> method()
> {code}
> I get the following error:
> {noformat}
> Exception thrown
> java.lang.BootstrapMethodError: call site initialization exception
> at java.lang.invoke.CallSite.makeSite(CallSite.java:341)
> at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:307)
> at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:297)
> at ConsoleScript33.method(ConsoleScript33:5)
> at ConsoleScript33.run(ConsoleScript33:9)
> at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:265)
> at groovy.lang.GroovyShell.run(GroovyShell.java:378)
> at groovy.lang.GroovyShell.run(GroovyShell.java:357)
> at groovy.lang.GroovyShell.run(GroovyShell.java:173)
> at groovy.lang.GroovyShell$run$0.call(Unknown Source)
> at groovy.ui.Console$_runScriptImpl_closure18.doCall(Console.groovy:1118)
> at groovy.ui.Console$_runScriptImpl_closure18.doCall(Console.groovy)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:103)
> at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
> at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1037)
> at groovy.lang.Closure.call(Closure.java:419)
> at groovy.lang.Closure.call(Closure.java:413)
> at groovy.lang.Closure.run(Closure.java:500)
> at java.lang.Thread.run(Thread.java:748)
> Caused by: java.lang.invoke.LambdaConversionException: Incorrect number of parameters for instance method invokeVirtual ConsoleScript33$_method_lambda1.doCall:(ConsoleScript33,Object,Object)Object; 2 captured parameters, 1 functional interface method parameters, 3 implementation parameters
> at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:193)
> at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
> at java.lang.invoke.CallSite.makeSite(CallSite.java:302)
> ... 23 more
> {noformat}
> We should produce a sensible error message in this case.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)