jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
groovy
  • groovy
  • GROOVY-2756 create new user overwritable operator...
  • GROOVY-2330

GString vs String equality in collections

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.1-rc-3
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

GStrings are one of the big groovy features. But there current equals behavior in collections makes them useless for many use cases. Very confusing is also the behavioral difference between lists and other collections.

All tests fail except the first one. (Tests run against rev 9408)

class StringVersusGStringEqualsInCollections extends GroovyTestCase {

    String string
    GString gString

    void setUp() {
        def g = 'g'
        string = 'groovy'
        gString = "${g}roovy"
    }

    void testEqualsInList() {
        assertEquals([string], [gString])
    }

    void testEqualsInSet() {
        assertEquals([string] as Set, [gString] as Set)
    }

    void testKeyEqualsInMap() {
        String someValue = 'somevalue'
        Map stringMap = [(string): someValue]
        Map gStringMap = [(gString): someValue]
        assertEquals(stringMap, gStringMap)
    }

    void testValueEqualsInMap() {
        String someKey = 'somekey'
        Map stringMap = [(someKey): string]
        Map gStringMap = [(someKey): gString]
        assertEquals(stringMap, gStringMap)
    }
}

Issue Links

is related to

Bug - A problem which impairs or prevents the functions of the product. GROOVY-951 Accessing Map elements using a GroovyString

  • Minor - Minor loss of function, or other problem where easy workaround is present.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.
relates to

Bug - A problem which impairs or prevents the functions of the product. GROOVY-2331 Println behavior for collections, strings and gstrings [minor breaking change]

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Hans Dockter added a comment - 25/Nov/07 6:13 PM

I forget to set 'fix for' to 1.1

Show
Hans Dockter added a comment - 25/Nov/07 6:13 PM I forget to set 'fix for' to 1.1
Andres Almiray made changes - 27/Nov/07 12:32 AM
Field Original Value New Value
Link This issue is related to GROOVY-951 [ GROOVY-951 ]
Andres Almiray made changes - 27/Nov/07 12:38 AM
Link This issue relates to GROOVY-2331 [ GROOVY-2331 ]
blackdrag blackdrag made changes - 16/Apr/08 11:10 AM
Parent GROOVY-2756 [ 66231 ]
Issue Type Bug [ 1 ] Sub-task [ 7 ]
blackdrag blackdrag made changes - 22/Apr/08 6:46 AM
Priority Blocker [ 1 ] Major [ 3 ]
Hide
Permalink
Pascal Schumacher added a comment - 01/Jan/13 9:05 AM

As of Groovy 2.0.6 only

void testKeyEqualsInMap() {
	String someValue = 'somevalue'
	Map stringMap = [(string): someValue]
	Map gStringMap = [(gString): someValue]
	assert stringMap == gStringMap
}

fails, the three other tests succeed.

Show
Pascal Schumacher added a comment - 01/Jan/13 9:05 AM As of Groovy 2.0.6 only void testKeyEqualsInMap() { String someValue = 'somevalue' Map stringMap = [(string): someValue] Map gStringMap = [(gString): someValue] assert stringMap == gStringMap } fails, the three other tests succeed.
Hide
Permalink
blackdrag blackdrag added a comment - 02/Jan/13 1:39 AM

Pascal, a change in DefaultGroovyMethods#equals(Map,Map) to for example iterate over the Map.Entry and use coerced compare would resolve this. But there is a second part to this issue... even ignoring where it is sorted in. The key is a GString and not a String, thus anything that does not use our compare will fail. If you for example had your own structure and used a GString instead of a String, then you may land in that trap. Or if you have Javacode manipulating the map, you get a similar problem. In the past it was suggested to automatically convert the gstring to a string, but that has problems as well.

Show
blackdrag blackdrag added a comment - 02/Jan/13 1:39 AM Pascal, a change in DefaultGroovyMethods#equals(Map,Map) to for example iterate over the Map.Entry and use coerced compare would resolve this. But there is a second part to this issue... even ignoring where it is sorted in. The key is a GString and not a String, thus anything that does not use our compare will fail. If you for example had your own structure and used a GString instead of a String, then you may land in that trap. Or if you have Javacode manipulating the map, you get a similar problem. In the past it was suggested to automatically convert the gstring to a string, but that has problems as well.
Hide
Permalink
Pascal Schumacher added a comment - 02/Jan/13 2:41 AM

Thanks for the explanation Jochen.

I think the current behavior is o.k..

I just wondered why one of the most popular issues hasn't been updated in a very long time and what the current status was so i rerun the tests.

As the other problems have been solved, i guess this issue could be closed.

Show
Pascal Schumacher added a comment - 02/Jan/13 2:41 AM Thanks for the explanation Jochen. I think the current behavior is o.k.. I just wondered why one of the most popular issues hasn't been updated in a very long time and what the current status was so i rerun the tests. As the other problems have been solved, i guess this issue could be closed.

People

  • Assignee:
    Unassigned
    Reporter:
    Hans Dockter
Vote (13)
Watch (9)

Dates

  • Created:
    25/Nov/07 4:04 PM
    Updated:
    02/Jan/13 2:41 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.