Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3198

Equal instances of an @Immutable class give different values when used as map keys

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6-beta-2
    • 1.6-rc-1, 1.7-beta-1
    • None
    • None

    Description

      Two equal instances of an @Immutable class should produce the same value when used as a map key. This is not the case, even though their hash codes are equal.
      The last assert below fails, though it should succeed.

      @Immutable
      final class Foo {
          String bar
      }
      
      foo1 = new Foo('bar')
      foo2 = new Foo('bar')
      assert foo1 == foo2
      assert foo1.hashCode() == foo2.hashCode()
      fooMap = [(foo1) : 1]
      assert fooMap[foo1] == 1
      assert fooMap[foo2] == 1 // Fails!!!
      

      Attachments

        Activity

          People

            paulk Paul King
            torda Tord Alenljung
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: