title: Groovy collect returning GString in a Jenkins Workflow script
body: <p>It seems that in the following piece of code:</p>
  
  <pre><code>def formattedPaths = affectedFiles.collect {
      "${it.editType.name} ${it.path}"
  }
  </code></pre>
  
  <p>at least sometimes <code>formattedPaths</code> evaluates to a GString instead of a List. This piece of code is a fragment of a larger Jenkins Workflow script, something like:</p>
  
  <pre><code>node {
       currentBuild.rawBuild.changeSets[0].collect { 
           """&lt;b&gt;${it.user}&lt;/b&gt; @ rev. ${it.revision}: ${it.msg}
           ${affectedFilesLog(it.affectedFiles)}"""
       }
  }
  
  def affectedFilesLog(affectedFiles) {
      println "Affected files [${affectedFiles.class}]: $affectedFiles"
      def formattedPaths = affectedFiles.collect {
          "${it.editType.name} ${it.path}"
      }
  
      println "formattedPaths [${formattedPaths.class}]: $formattedPaths"
      formatItemList(formattedPaths)
  }
  
  def formatItemList(list) {
      if (list) {
          return list.join('\n')
      }
  
      return  '(none)'
  }
  </code></pre>
  
  <p>Running this script in Jenkins produces output:</p>
  
  <pre><code>Running: Print Message
  Affected files [class java.util.ArrayList]: [hudson.scm.SubversionChangeLogSet$Path@5030a7d8]
  Running: Print Message
  formattedPaths [class org.codehaus.groovy.runtime.GStringImpl]: edit my/path/flow.groovy
  (...)
  groovy.lang.MissingMethodException: No signature of method: java.lang.String.join() is applicable for argument types: (java.lang.String) values: [
  ]
  </code></pre>
  
  <p>And this makes me believe that in the code:</p>
  
  <pre><code>println "Affected files [${affectedFiles.class}]: $affectedFiles"
  def formattedPaths = affectedFiles.collect {
      "${it.editType.name} ${it.path}"
  }
  
  println "formattedPaths [${formattedPaths.class}]: $formattedPaths"
  </code></pre>
  
  <p><code>affectedFiles</code> is <code>ArrayList</code> (script output <code>Affected files [class java.util.ArrayList]: [hudson.scm.SubversionChangeLogSet$Path@5030a7d8]</code> in the output)</p>
  
  <p>but result of running collect method on it - assigned to <code>formattedPaths</code> - is a GString (output: <code>formattedPaths [class org.codehaus.groovy.runtime.GStringImpl]: edit my/path/flow.groovy</code>)</p>
  
  <p>Shouldn't the collect method always return a List?</p>