Thanks. It took me a couple of moments to work what you meant by
overflowing the int type. :-)
Greg Brown wrote:
> Similar to the span issue, the length of an int range could overflow the int
> type so it could be greater than Integer.MAX_VALUE. However, this code has
> the same issue as Span, since without the cast to long, the calculation will
> be incorrect.
>
> I believe the check is necessary because Sequence#getLength() (which
> NumericSpinnerData implements via List) returns an int, which would overflow
> if the range was sufficiently large.
>
> I'll check in a fix for this and the Span issue momentarily.
>
> G
>
> On Jun 18, 2010, at 7:30 AM, Noel Grandin wrote:
>
>
>> Hi
>>
>> In the code below
>>
>> public NumericSpinnerData(int lowerBound, int upperBound, int
>> increment) {
>> if (lowerBound >= upperBound) {
>> throw new IllegalArgumentException("Lower bound must be less
>> than upper bound.");
>> }
>>
>> long length = ((upperBound - lowerBound) / increment) + 1;
>>
>>
>>>> if (length > Integer.MAX_VALUE) {
>>>> throw new IllegalArgumentException("Bounded range is too
>>>>
>> large.");
>>
>>>> }
>>>>
>> this.lowerBound = lowerBound;
>> this.upperBound = upperBound;
>> this.increment = increment;
>> }
>>
>> The "if" statement marked by ">>" can never trigger because when you
>> divide an "int" by another "int", the answer is by definition less than
>> Integer.MAX_VALUE.
>>
>> Perhaps this code was intended for use in a floating point spinner model
>> class? (which is something that we're missing, BTW).
>>
>> Regards, Noel.
>>
>>
>