Details

    • Type: Sub-task Sub-task
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1-rc-3
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:
      None

      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

          Activity

          Mark Thomas made changes -
          Workflow jira [ 12967500 ] Default workflow, editable Closed status [ 12975224 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12731394 ] Default workflow, editable Closed status [ 12743322 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Jochen Theodorou made changes -
          Component/s groovy-runtime [ 16250 ]
          Hide
          Pascal Schumacher added a comment -

          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 - 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.
          Hide
          Jochen Theodorou added a comment -

          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
          Jochen Theodorou added a comment - 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
          Pascal Schumacher added a comment -

          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 - 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.
          Jochen Theodorou made changes -
          Priority Blocker [ 1 ] Major [ 3 ]
          Jochen Theodorou made changes -
          Issue Type Bug [ 1 ] Sub-task [ 7 ]
          Parent GROOVY-2756 [ 66231 ]
          Andres Almiray made changes -
          Link This issue relates to GROOVY-2331 [ GROOVY-2331 ]
          Andres Almiray made changes -
          Field Original Value New Value
          Link This issue is related to GROOVY-951 [ GROOVY-951 ]
          Hide
          Hans Dockter added a comment -

          I forget to set 'fix for' to 1.1

          Show
          Hans Dockter added a comment - I forget to set 'fix for' to 1.1
          Hans Dockter created issue -

            People

            • Assignee:
              Unassigned
              Reporter:
              Hans Dockter
            • Votes:
              7 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Development