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

ClassCastException when calling DefaultTypeTransformation#compareEqual

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.6
    • 2.4.8
    • None
    • None

    Description

      It appears that comparing two objects that both implement comparable with DefaultTypeTransformation#compareEqual is not safe in all cases. Consider enums for example, which throw exceptions when compared to differing classes.

      This is using Eclipse Collections for pairs but the idea is the same in general.

          enum E1 {A, B, C}
          enum E2 {D, E, F}
      
          def "test groovy oddness"() {
              when:
              def test = DefaultTypeTransformation.compareEqual(
                  Tuples.pair(E1.A, 1), 
                  Tuples.pair(E2.D, 1))
      
              then:
              assert test == false
          }
      

      Stacktrace

      java.lang.ClassCastException
      	at java.lang.Enum.compareTo(Enum.java:180)
      	at java.lang.Enum.compareTo(Enum.java:55)
      	at org.eclipse.collections.impl.tuple.PairImpl.compareTo(PairImpl.java:95)
      	at org.eclipse.collections.impl.tuple.PairImpl.compareTo(PairImpl.java:22)
      	at com.GroovyTests.test groovy oddness(GroovyTests.groovy:36)
      

      Attachments

        Issue Links

          Activity

            People

              paulk Paul King
              aewhite Andrew White
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: