Oct. 18th, 2012

scala fun

Oct. 18th, 2012 10:27 am
juan_gandhi: (Default)
(from scala-user)

Can someone tell me whether this "gotcha" is type-unsafe or am I just not realizing something? This bit me in production code today (via java interop).
scala> def x: java.math.BigDecimal = null
x: java.math.BigDecimal

scala> def y = Option[BigDecimal](x) orElse Option[BigDecimal](x)
y: Option[BigDecimal]

scala> for (z <- y) println(z)
java.lang.NullPointerException


Year 2020:
...
java.lang.IllegalArgumentException: null value for BigDecimal
  at scala.math.BigDecimal.(BigDecimal.scala:406)
  at scala.math.BigDecimal$.apply(BigDecimal.scala:335)
  at scala.math.BigDecimal$.apply(BigDecimal.scala:332)
  at scala.math.BigDecimal$.javaBigDecimal2bigDecimal(BigDecimal.scala:347)
  at .y(:12)
  ... 28 elided

juan_gandhi: (Default)
zipper ("hello", "world")
  % down _1
  % fromWithin traverse
  % focus .~ 'J'
  % rightmost
  % focus .~ 'y'
  % rezip
("Jelly", "world")

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

November 2025

S M T W T F S
       1
23456 7 8
9 1011 12 1314 15
16171819 20 2122
23 24 252627 28 29
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Dec. 1st, 2025 12:08 am
Powered by Dreamwidth Studios