Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Pointer Exception in Range.Double.toArray #8782

Closed
scabug opened this issue Aug 6, 2014 · 3 comments
Closed

Null Pointer Exception in Range.Double.toArray #8782

scabug opened this issue Aug 6, 2014 · 3 comments

Comments

@scabug
Copy link

scabug commented Aug 6, 2014

The following code snippet throws a NPE

val possibleValues = Range.Double.inclusive(5.0,10.0,5.0/3.0).toArray

The strackTrace is

java.lang.IndexOutOfBoundsException: 3
  at scala.collection.immutable.NumericRange.apply(NumericRange.scala:112)
  at scala.collection.immutable.NumericRange$$anon$1.apply(NumericRange.scala:165)
  at scala.collection.IndexedSeqLike$Elements.next(IndexedSeqLike.scala:65)
  at scala.collection.IterableLike$class.copyToArray(IterableLike.scala:253)
  at scala.collection.AbstractIterable.copyToArray(Iterable.scala:54)
  at scala.collection.TraversableOnce$class.copyToArray(TraversableOnce.scala:263)
  at scala.collection.AbstractTraversable.copyToArray(Traversable.scala:104)
  at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:271)
  at scala.collection.AbstractTraversable.toArray(Traversable.scala:104)
@scabug
Copy link
Author

scabug commented Aug 6, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8782?orig=1
Reporter: Shiti Saxena (Shiti)
Affected Versions: 2.9.3, 2.10.4, 2.11.0, 2.11.1, 2.11.2

@scabug
Copy link
Author

scabug commented Aug 6, 2014

Shiti Saxena (Shiti) said (edited on Aug 6, 2014 7:04:14 AM UTC):
When using the to method to generate a Double Range, the result was is not the same as Range.Double.

scala> val possibleValues1 = Range.Double.inclusive(5.0,10.0,5.0/3.0)
possibleValues1: scala.collection.immutable.NumericRange[Double] = NumericRange(5.0, 6.666666666666667, 8.333333333333334)

scala> val possibleValues2 = 5.0 to (10.0,5.0/3.0)
possibleValues2: scala.collection.immutable.NumericRange.Inclusive[Double] = NumericRange(5.0, 6.666666666666667, 8.333333333333334, 10.0)

scala> possibleValues2.toArray
res0: Array[Double] = Array(5.0, 6.666666666666667, 8.333333333333334, 10.0)

I have noticed that Range.Double internally generates a Range using Range.BigDecimal and then converting it to Double (code) whereas FractionalProxy.to creates a NumericRange of Type Double,

  def to(end: T): ResultWithoutStep  = new Range.Partial(NumericRange.inclusive(self, end, _))

Which of the two is correct or expected behavior?

@xuwei-k
Copy link

xuwei-k commented Sep 14, 2018

in 2.12.6

Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181).
Type in expressions for evaluation. Or try :help.

scala> Range.Double.inclusive(5.0,10.0,5.0/3.0).toArray
<console>:12: warning: method inclusive in object Double is deprecated (since 2.12.6): use Range.BigDecimal.inclusive instead
       Range.Double.inclusive(5.0,10.0,5.0/3.0).toArray
                    ^
res0: Array[Double] = Array(5.0, 6.666666666666667, 8.333333333333334)

Range.Double removed since Scala 2.13 scala/scala#6468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants