Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.5.6, 1.6-beta-1
-
None
-
None
Description
A mixed type int/long range throws a ClassCastException when printed.
script.groovy
def start = Integer.MAX_VALUE def finish = Integer.MAX_VALUE + 2L def r = (start..finish) println r.getClass() // class groovy.lang.ObjectRange println r.getFrom().getClass() // class java.lang.Integer println r.getTo().getClass() // class java.lang.Long println r.toString() // 2147483647..2147483649 println r //java.lang.ClassCastException: java.lang.Integer println ('Range is ' + r.toString()) // Range is 2147483647..2147483649 println ('Range is ' + r) //java.lang.ClassCastException: java.lang.Integer
BTW, I assume that converting the range to a list for printing happens on purpose:
script.groovy
def start = 0 def finish = 2 def r = (start..finish) println r.toString() // 0..2 println r // [0, 1, 2]
Seems a bit strange to me, but well...