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

StringGroovyMethods.findAll(String, Pattern, Closure) and StringGroovyMethods.findAll(CharSequence, Pattern, Closure) is with @ClosureParams incorrect

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0.0-alpha-4, 2.5.6
    • 3.0.0-beta-1, 2.5.7
    • groovy-runtime
    • None

    Description

      StringGroovyMethods.find(arg1, arg2, Closure) and  StringGroovyMethods.findAll(arg1, arg2, Closure) is with @ClosureParams(value=SimpleType.class, options="java.lang.String[]") but the Closure receive a instance of List<String> from DefaultGroovyMethods.collect(matcher, closure), this cause a Exception

      Caught: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List
      java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.List
      at CLass.m(brasileiro.groovy:7)
      at CLass$m.call(Unknown Source)
      at brasileiro.run(brasileiro.groovy:13)
      

      Exemple:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class CLass {
          List m(){
              String string = 'ABCD'
              //ClassCastException here
              return string.findAll(/(A)(B)(C)/) { String[] group->
                   return group[2]
              }
          }
      }
      
      new CLass().m()

       

      Attachments

        1. image.png
          25 kB
          Henrique Mota

        Activity

          People

            paulk Paul King
            henriquemota Henrique Mota
            Votes:
            0 Vote for this issue
            Watchers:
            3 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 - 0.5h
                0.5h