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

GPars collection methods don't work with @CompileStatic

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.1.1
    • Fix Version/s: None
    • Component/s: GroovyScriptEngine
    • Environment:
      using Gpars 1.0 and groovy 2.1.1

      Description

      When attempting to use both @CompileStatic and GPars (either GParsPool or GParsExecutorPool) there is a compile time error.

      The following sample code:

      Example test case showing a few examples that should work
      import groovy.transform.CompileStatic
      import groovyx.gpars.GParsExecutorsPool
      
      import java.util.concurrent.ForkJoinPool
      
      @CompileStatic
      class GParsStatic {
          def foo = ["foo", "bar", "blarg", "doo", "woop", "bliz"]
      
          ForkJoinPool forkJoinPool = new ForkJoinPool()
      
          void testEachParallel() {
              GParsExecutorsPool.withExistingPool(forkJoinPool) {
                  foo.eachParallel { String entry ->
                      println("${entry}")
                  }
              }
          }
          void testEachWithIndexParallel() {
              GParsExecutorsPool.withExistingPool(forkJoinPool) {
                  foo.eachWithIndexParallel { String entry, int i ->
                      println("${entry} at index ${i}")
                  }
              }
          }
      
      }
      

      produces the errors:

      Groovyc: [Static type checking] - Cannot find matching method java.lang.Object#eachParallel(groovy.lang.Closure). Please check if the declared type is right and if the method exists.
      Groovyc: [Static type checking] - Cannot find matching method java.lang.Object#eachWithIndexParallel(groovy.lang.Closure). Please check if the declared type is right and if the method exists.
      

      Since this is a compile-time error, I haven't created a junit test for it (I do have a simple spock test, if it helps

      "simple spock test that calls the methods that should work"
      import spock.lang.Specification
      
      
      class GParsStaticSpec extends Specification{
          def "test that method runs"() {
          setup:
              GparsStaticCompile gparsStaticCompile = new GparsStaticCompile()
          when:
              gparsStaticCompile.testEachWithIndexParallel()
              gparsStaticCompile.testEachParallel()
          then:
              notThrown(Exception)
          }
      }
      
      

      If the

      {monospaced}@CompileStatic{monospaced}

      is removed, the class compiles and the methods run properly.

        Attachments

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              ryangardner Ryan Gardner
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: