any ideas?

62 views
Skip to first unread message

Vlad Patryshev

unread,
Oct 18, 2016, 11:41:35 AM10/18/16
to scala-user

scala> def x: java.math.BigDecimal = null

x: java.math.BigDecimal

scala> Option(x)

res6: Option[java.math.BigDecimal] = None

scala> Option[BigDecimal](x)

java.lang.NullPointerException

Thanks,
-Vlad

Oliver Ruebenacker

unread,
Oct 18, 2016, 11:53:14 AM10/18/16
to Vlad Patryshev, scala-user

     Hello,

  Not sure what is going on here, but note that BigDecimal is scala.math.BigDecimal, not java.mathBigDecimal.

     Best, Oliver

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

Vlad Patryshev

unread,
Oct 18, 2016, 11:54:04 AM10/18/16
to Oliver Ruebenacker, scala-user
It should not make any difference, I think.

Thanks,
-Vlad

Ionuț G. Stan

unread,
Oct 18, 2016, 11:58:17 AM10/18/16
to Vlad Patryshev, Oliver Ruebenacker, scala-user
However, it does:

scala> def x: java.math.BigDecimal = null
x: java.math.BigDecimal

scala> x: scala.math.BigDecimal
java.lang.IllegalArgumentException: null value for BigDecimal
at scala.math.BigDecimal.<init>(BigDecimal.scala:406)
at scala.math.BigDecimal$.apply(BigDecimal.scala:334)
at scala.math.BigDecimal$.apply(BigDecimal.scala:331)
at scala.math.BigDecimal$.javaBigDecimal2bigDecimal(BigDecimal.scala:346)
... 32 elided

https://github.com/scala/scala/blob/v2.11.8/src/library/scala/math/BigDecimal.scala#L406

On 18/10/2016 18:53, Vlad Patryshev wrote:
> It should not make any difference, I think.
>
> Thanks,
> -Vlad
>
> On Tue, Oct 18, 2016 at 8:53 AM, Oliver Ruebenacker <cur...@gmail.com
> <mailto:cur...@gmail.com>> wrote:
>
>
> Hello,
>
> Not sure what is going on here, but note that BigDecimal is
> scala.math.BigDecimal, not java.mathBigDecimal.
>
> Best, Oliver
>
> On Tue, Oct 18, 2016 at 11:41 AM, Vlad Patryshev
> <vpatr...@gmail.com <mailto:vpatr...@gmail.com>> wrote:
>
> scala> def x: java.math.BigDecimal = null
>
> x: java.math.BigDecimal
>
> scala> Option(x)
>
> res6: Option[java.math.BigDecimal] = None
>
> scala> Option[BigDecimal](x)
>
> java.lang.NullPointerException
>
> Thanks,
> -Vlad
>
> --
> You received this message because you are subscribed to the
> Google Groups "scala-user" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to scala-user+...@googlegroups.com
> <mailto:scala-user+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
>
>
> --
> Oliver Ruebenacker
> Senior Software Engineer, Diabetes Portal
> <http://www.type2diabetesgenetics.org/>, Broad Institute
> <http://www.broadinstitute.org/>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scala-user+...@googlegroups.com
> <mailto:scala-user+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


--
Ionuț G. Stan | http://igstan.ro | http://bucharestfp.ro

Daniel Barclay

unread,
Oct 18, 2016, 5:34:18 PM10/18/16
to Ionuț G. Stan, Vlad Patryshev, Oliver Ruebenacker, scala-user
Ionuț G. Stan wrote:
> However, it does:
>
> scala> def x: java.math.BigDecimal = null
> x: java.math.BigDecimal
>
> scala> x: scala.math.BigDecimal
Is there an implicit conversion happening there and trying to dereference the null value?

Daniel
> To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.

Ionuț G. Stan

unread,
Oct 18, 2016, 6:36:13 PM10/18/16
to Daniel Barclay, Vlad Patryshev, Oliver Ruebenacker, scala-user
On 19/10/2016 00:34, Daniel Barclay wrote:
> Ionuț G. Stan wrote:
>> However, it does:
>>
>> scala> def x: java.math.BigDecimal = null
>> x: java.math.BigDecimal
>>
>> scala> x: scala.math.BigDecimal
> Is there an implicit conversion happening there and trying to dereference the null value?

Yes:
https://github.com/scala/scala/blob/v2.11.8/src/library/scala/math/BigDecimal.scala#L346
Reply all
Reply to author
Forward
0 new messages