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

List.intersect changes behavior from Groovy 2.4 and Groovy 2.5+

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Bug
    • 3.0.5, 2.5.13
    • None
    • groovy-runtime
    • None
    • Ubuntu 18.04.5 LTS
      OpenJDK Java 1.8.0_265 (Private Build 25.265-b01)
      Gradle 5.6.3

    Description

      Description

      List.intersect preserves the ordering of the source list in Groovy 2.4 but instead takes the ordering of the intersecting list. This can lead to unexpected behavior in Groovy applications as code migrates to newer versions of Groovy.

      Example code

      // Passes assertion in Groovy 2.4.20 but fails in Groovy 2.5.13 and 3.0.5
      
      assert ['a', 'b'].intersect(['c', 'b', 'a']) == ['a', 'b']

      Expected behavior

      The order of the first list is preserved.

      Actual behavior

      The order of the second list takes precedence.

      Groovy version matrix

      Groovy version Behavior
      2.4.20 Assertion passes
      2.5.13 Assertion fails (order reversed)
      3.0.5 Assertion fails (order reversed)

      Attachments

        Activity

          People

            Unassigned Unassigned
            samrocketman Sam Gleske
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: