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

disjoint() does not work correctly if objects don't implement Comparable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.4
    • 2.4.7
    • groovy-runtime
    • None

    Description

      class Foo {
      
          private String name
      
          Foo(String name) {
              this.name = name
          }
      
          public boolean equals(Object o) {
              if (this == o) return true
              if (o == null || getClass() != o.getClass()) return false
              Foo that = (Foo) o
              return Objects.equals(name, that.name)
          }
      
          public int hashCode() {
              return Objects.hash(name)
          }
      
      }
      
      def a = [new Foo("foo")]
      def b = [new Foo("foo")]    
      assert !a.disjoint(b)
      

      If disjoint() is used on a list with objects not implementing Comparable the wrong result is returned.
      intersect() shows the same wrong behavior.

      It's looks like the NumberAwareComparator not implementing the equals case as of commit 286532c is the problem.

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              tahlers Tobias Ahlers
              Votes:
              5 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: