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

Concatenating an empty list to a GString throws a MethodSelectionException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.7.5
    • 1.8.2
    • None
    • None

    Description

      A MethodSelectionException is thrown when appending an empty list to a GString that contains a ${} expression. Note that no exception is thrown if the GString does not contain a ${} expression or if the list is nonempty. The exception thrown is:

      Caught: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method plus() to invoke from this list:
        public groovy.lang.GString groovy.lang.GString#plus(groovy.lang.GString)
        public groovy.lang.GString groovy.lang.GString#plus(java.lang.String)
      

      No other concatenation I've tried has this behavior. So the following line throws the exception:

      "GString concat ${'a'}" + []

      None of the following throw anything:

      "GString concat ${'a'}" + ['abc']  // Concatenating a nonempty list
      "GString concat " + []             // Concatenating an empty list, but not using ${} in the GString
      
      // Concatenating various other object types
      ['abc', '', null, [:], 0, 1, false, new Object[0]].each { "GString concat ${'a'}" + it }
      

      I would expect the behavior of appending an empty list to be consistent with appending any other list (or object type).

      Attachments

        Activity

          People

            paulk Paul King
            mjjustin M. Justin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: