groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew White (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-7876) ClassCastException when calling DefaultTypeTransformation#compareEqual
Date Tue, 28 Jun 2016 13:47:57 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-7876?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Andrew White updated GROOVY-7876:
---------------------------------
    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. 

{code}
    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
    }
{code}

Stacktrace

{code}
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)
{code}

  was:
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. 

{code}
    enum E1 {A, B, C}
    enum E2 {D, E, F}

    def "test groovy oddness"() {
        when:
        def test = GroovyRuntimeUtil.equals(
            Tuples.pair(E1.A, 1), 
            Tuples.pair(E2.D, 1))

        then:
        assert test == false
    }
{code}

Stacktrace

{code}
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)
{code}


> ClassCastException when calling DefaultTypeTransformation#compareEqual
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-7876
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7876
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.6
>            Reporter: Andrew White
>
> 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. 
> {code}
>     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
>     }
> {code}
> Stacktrace
> {code}
> 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)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message