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

          No work has yet been logged on this issue.

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development