Groovy
  1. Groovy
  2. GROOVY-951

Accessing Map elements using a GroovyString

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.0-JSR-2
    • Fix Version/s: 1.5.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      Windows XP Service Pack 2, but others have reported having the same issue

      Description

      The underlying Java Map object uses Equals to determine if two keys are the same. But a java String is not equal to a GString.

      Here is an example script and it's output:
      def animalType = "dog"
      def map = [:]
      map.put(animalType, "Spike")

      println ("key = $animalType")
      println ("animalName = " + map.get("dog")) // 1
      println "animalName = " + map.get("$animalType") // 2
      println "animalName = " + map.get("$

      {animalType}

      ") // 3
      println "animalName = " + map.get(animalType) // 4

      C:\groovy>groovy -version
      Groovy Version: 1.0-jsr-02 JVM: 1.4.2_06-b03
      C:\groovy>groovy test.groovy
      key = dog
      animalName = Spike
      animalName = null
      animalName = null
      animalName = Spike

      Notice the null output for lines 2 and 3.

        Issue Links

          Activity

          Shawn Kessler created issue -
          Andres Almiray made changes -
          Field Original Value New Value
          Link This issue relates to GROOVY-2330 [ GROOVY-2330 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.5.1 [ 13923 ]
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Won't Fix [ 2 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12730100 ] Default workflow, editable Closed status [ 12742095 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12968581 ] Default workflow, editable Closed status [ 12976365 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              Shawn Kessler
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development