Groovy
  1. Groovy
  2. GROOVY-4916

Set equality fails if null elements are present

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.1
    • Component/s: None
    • Labels:
      None
    • Environment:
      java version "1.6.0_24"
      Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
      Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
      Ubuntu 10.04

      Description

      The following assertions work as expected in groovy 1.7.10, but fail in groovy 1.8.0

      First case:

      def foo = [ "a", null ] as Set
      assert foo.equals( foo )
      

      Second case:

      def foo = [ "a", null ] as Set
      def bar = [ "a", null ] as Set
      assert foo == bar
      assert foo.equals( bar )
      

      foo == foo happens to work, which leads me to believe that == tests for object identity first.

      I can workaround by testing Set equality using brute force, but it's very surprising.

        Activity

        Ray A. Conner created issue -
        Paul King made changes -
        Field Original Value New Value
        Environment java version "1.6.0_24"
        Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
        Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
        Ubuntu 10.04
        Paul King made changes -
        Comment [ Sorry, should have let you know about my environment.

        java version "1.6.0_24"
        Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
        Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

        Ubuntu 10.04
        ]
        Hide
        Paul King added a comment -

        add code tags, move environment info

        Show
        Paul King added a comment - add code tags, move environment info
        Paul King made changes -
        Description The following assertions work as expected in groovy 1.7.10, but fail in groovy 1.8.0

        First case:
          def foo = [ "a", null ] as Set
          assert foo.equals( foo )

        Second case:
          def foo = [ "a", null ] as Set
          def bar = [ "a", null ] as Set
          assert foo == bar
          assert foo.equals( bar )

        foo == foo happens to work, which leads me to believe that == tests for object identity first.

        I can workaround by testing Set equality using brute force, but it's very surprising.
        The following assertions work as expected in groovy 1.7.10, but fail in groovy 1.8.0

        First case:
        {code}
        def foo = [ "a", null ] as Set
        assert foo.equals( foo )
        {code}

        Second case:
        {code}
        def foo = [ "a", null ] as Set
        def bar = [ "a", null ] as Set
        assert foo == bar
        assert foo.equals( bar )
        {code}

        foo == foo happens to work, which leads me to believe that == tests for object identity first.

        I can workaround by testing Set equality using brute force, but it's very surprising.
        Hide
        Paul King added a comment - - edited

        There was/is no special Set equals handling in Groovy 1.7, so it just gets the default Java equals (which happens to be AbstractSet#equals which works in your case but wouldn't work in other places where Groovy coerces values from related types, e.g. if you had 3 and 3.0 in two sets). Groovy 1.8.0 had special equals handling but it was broken for sets containing null. It has been fixed now. Thanks for filing the report.

        Show
        Paul King added a comment - - edited There was/is no special Set equals handling in Groovy 1.7, so it just gets the default Java equals (which happens to be AbstractSet#equals which works in your case but wouldn't work in other places where Groovy coerces values from related types, e.g. if you had 3 and 3.0 in two sets). Groovy 1.8.0 had special equals handling but it was broken for sets containing null. It has been fixed now. Thanks for filing the report.
        Paul King made changes -
        Resolution Fixed [ 1 ]
        Assignee Paul King [ paulk ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.8.1 [ 17223 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733843 ] Default workflow, editable Closed status [ 12745641 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12971366 ] Default workflow, editable Closed status [ 12979065 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        17h 56m 1 Paul King 09/Jul/11 07:29
        Resolved Resolved Closed Closed
        12d 12h 37m 1 Paul King 21/Jul/11 20:06

          People

          • Assignee:
            Paul King
            Reporter:
            Ray A. Conner
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development