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

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

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.4
    • Fix Version/s: 2.4.7
    • Component/s: groovy-runtime
    • Labels:
      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

            • Assignee:
              paulk Paul King
              Reporter:
              tahlers Tobias Ahlers

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment