Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.7.0
-
Fix Version/s: 1.6.8, 1.7.1, 1.8-beta-1
-
Component/s: None
-
Labels:None
-
Environment:tested for 1.7.0 and 1.6.0
-
Testcase included:yes
-
Number of attachments :
Description
Example 1:
assertFalse(new Object() == 1) // this is ok
assertFalse(1 == new Object()) // this throws a ClassCastException, because Groovy redirects the call to java.lang.Integer.compareTo(Integer i)
Example 2:
enum MyEnum
{ A, B, C }assertFalse(new Object() == MyEnum.A) // this is ok
assertFalse(MyEnum.A == new Object()) // this throws a ClassCastException, because Groovy redirects the call to java.lang.Enum.compareTo(E e) where E extends java.lang.Enum<E>
In the corner case of a Comparable instance being comparedTo an Object instance, the comparison made by DefaultTypeTransformation#compareToWithEqualityCheck() was becoming Object.isAssignableFrom(SomeComparableClass), which was not really serving any purpose, because all classes are assignable to Object. This meaningless condition was causing the issue in both the reported scenarios and has been fixed now.