Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
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
-
Number of attachments :
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("$
") // 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
- relates to
-
GROOVY-2330
GString vs String equality in collections
-
Activity
| Field | Original Value | New Value |
|---|---|---|
| Link | This issue relates to GROOVY-2330 [ GROOVY-2330 ] |
| Status | Open [ 1 ] | Closed [ 6 ] |
| Fix Version/s | 1.5.1 [ 13923 ] | |
| Resolution | Won't Fix [ 2 ] |
I think this issue is a duplicate of
GROOVY-626.