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

Map.inject() doesn't accept closure with 3 arguments (collector, key, value), only 2 (collector, Map.Entry)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0
    • 1.8.1
    • groovy-jdk
    • None

    Description

      Map.inject() only accepts Closure with 2 arguments - inject() collection object and Map.Entry. It would be nice to have it accepting a 3-arguments Closure: inject() collection object, key, value.

      groovy> assert [] == ['ss':'dd'].inject([]){ List l, Map.Entry e              -> l } 
      groovy> assert [] == ['ss':'dd'].inject([]){ List l, Object key, Object value -> l } 
       
      Exception thrown
      Jun 27, 2011 5:42:15 AM org.codehaus.groovy.runtime.StackTraceUtils sanitize
      
      WARNING: Sanitizing stacktrace:
      
      groovy.lang.MissingMethodException: No signature of method: ConsoleScript8$_run_closure2.doCall() is applicable for argument types: (java.util.ArrayList, java.util.LinkedHashMap$Entry) values: [[], ss=dd]
      Possible solutions: doCall(java.util.List, java.lang.Object, java.lang.Object)
      
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
      
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:885)
      
      	at groovy.lang.Closure.call(Closure.java:405)
      
      	at org.codehaus.groovy.runtime.DefaultGroovyMethods.inject(DefaultGroovyMethods.java:2939)
      
      	at org.codehaus.groovy.runtime.DefaultGroovyMethods.inject(DefaultGroovyMethods.java:2960)
      
      	at org.codehaus.groovy.runtime.dgm$329.invoke(Unknown Source)
      
      	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
      
      	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
      
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
      
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
      
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
      
      	at ConsoleScript8.run(ConsoleScript8:2)
      
      	at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
      
      	at groovy.lang.GroovyShell.run(GroovyShell.java:517)
      
      	at groovy.lang.GroovyShell.run(GroovyShell.java:172)
      
      	at groovy.lang.GroovyShell$run.call(Unknown Source)
      
      	at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:910)
      
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
      	at java.lang.reflect.Method.invoke(Method.java:597)
      
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:885)
      
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
      
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
      
      	at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy)
      
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
      	at java.lang.reflect.Method.invoke(Method.java:597)
      
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
      
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:885)
      
      	at groovy.lang.Closure.call(Closure.java:405)
      
      	at groovy.lang.Closure.call(Closure.java:399)
      
      	at groovy.lang.Closure.run(Closure.java:483)
      
      	at java.lang.Thread.run(Thread.java:662)
      
      groovy.lang.MissingMethodException: No signature of method: ConsoleScript8$_run_closure2.doCall() is applicable for argument types: (java.util.ArrayList, java.util.LinkedHashMap$Entry) values: [[], ss=dd]
      Possible solutions: doCall(java.util.List, java.lang.Object, java.lang.Object)
      
      	at ConsoleScript8.run(ConsoleScript8:2)
      

      Attachments

        Activity

          People

            paulk Paul King
            genie Evgeny Goldin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: