groovy
  1. groovy
  2. GROOVY-4882

Concatenating an empty list to a GString throws a MethodSelectionException

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.7.5
    • Fix Version/s: 1.8.2
    • Component/s: None
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      1

      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).

        Activity

        Hide
        John Wagenleitner added a comment -

        Just wanted to note that the attached testcase passes in Groovy 1.8.2 and above.

        Show
        John Wagenleitner added a comment - Just wanted to note that the attached testcase passes in Groovy 1.8.2 and above.
        Hide
        Paul King added a comment -

        I think this was "fixed" via other changes (possible GROOVY-4949). Please reopen if you can reproduce with a recent version of Groovy.

        Show
        Paul King added a comment - I think this was "fixed" via other changes (possible GROOVY-4949 ). Please reopen if you can reproduce with a recent version of Groovy.

          People

          • Assignee:
            Paul King
            Reporter:
            M. Justin
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: