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

Inferred parameter type of lambda expression for multi-dimensions array is not correct

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

      Description

      The type of strs is inferred as String, but its type should be String[]

      @groovy.transform.CompileStatic
      def test() {
          String[][] strsArray = new String[][] {
              new String[] {'a', 'b', 'c'},
              new String[] {'d', 'e', 'f'}
          }
          Arrays.stream(strsArray)
                      .limit(1)
                      .forEach(strs -> {
                          assert ['a', 'b', 'c'] == Arrays.asList(strs)
                      })
      }
      test()
      

      Error message

      java.lang.ClassCastException: class [Ljava.lang.String; cannot be cast to class java.lang.String ([Ljava.lang.String; and java.lang.String are in module java.base of loader 'bootstrap')
      
      	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
      
      	at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:199)
      
      	at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
      
      	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
      
      	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
      
      	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
      
      	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
      
      	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
      
      	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
      
      	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      
      	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
      
      	at ConsoleScript3.test(ConsoleScript3:7)
      
      	at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:318)
      
      	at ConsoleScript3.run(ConsoleScript3:13)
      
      	at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:257)
      
      	at groovy.lang.GroovyShell.run(GroovyShell.java:363)
      
      	at groovy.lang.GroovyShell.run(GroovyShell.java:342)
      
      	at groovy.lang.GroovyShell.run(GroovyShell.java:168)
      
      	at groovy.console.ui.Console$GroovySourceType.run(Console.groovy:1177)
      
      	at groovy.console.ui.Console.doRun(Console.groovy:1408)
      
      	at jdk.internal.reflect.GeneratedMethodAccessor81.invoke(Unknown Source)
      
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      
      	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:112)
      
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:331)
      
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:63)
      
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:203)
      
      	at groovy.console.ui.Console$_runScriptImpl_closure23.doCall(Console.groovy:1372)
      
      	at groovy.console.ui.Console$_runScriptImpl_closure23.doCall(Console.groovy)
      
      	at jdk.internal.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
      
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      
      	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:112)
      
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      
      	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:268)
      
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
      
      	at groovy.lang.Closure.call(Closure.java:419)
      
      	at groovy.lang.Closure.call(Closure.java:413)
      
      	at groovy.lang.Closure.run(Closure.java:501)
      
      	at java.base/java.lang.Thread.run(Thread.java:834)
      

        Attachments

          Activity

            People

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              daniel_sun Daniel Sun

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

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

                  Issue deployment