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

GString: document or coerce

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.6
    • 1.6-rc-1, 1.5.8, 1.7-beta-1
    • None
    • None

    Description

      GStrings show surprising behaviour when used as keys in collections or in comparisons. This lead to a lot of issues, e.g. (GROOVY-626, GROOVY-2332, GROOVY-2330, GROOVY-951, GROOVY-2660, GROOVY-1959). The situation is even worse with lazy evaluation of closures in GStrings (see attached script).

      So either

      Document that the user should

      • use GString#toString() instead of putting GString (as a key) into a collection, and
      • use GString#toString() instead of GString in comparisons with a String.

      Or

      Coerce arguments that are instanceof GString to String if the receiving parameter's type is not GString or a type derived from GString.

      I would prefer 1. over 2.

      Attachments

        1. gstringBehaviour.groovy
          1 kB
          Alexander Veit

        Activity

          People

            guillaume Guillaume Sauthier
            veita Alexander Veit
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: