Can somebody verify that this is indeed a bug or should I just raise it in the JIRA directly ?
The suggested workaround converting j.m.BigDecimal to Option[BigDecimal] does the trick
Thanks
Fernando Racca
Fernando Racca
--
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.
For more options, visit https://groups.google.com/groups/opt_out.
In 2.11, wrapping null in Scala's BigDecimal will not be allowed. You'll get an exception when you try.
I think this will "solve" all the problems. (null is not a valid numeric value anyway.)
--Rex
On Monday, 3 February 2014 21:53:59 UTC, Rex Kerr wrote:In 2.11, wrapping null in Scala's BigDecimal will not be allowed. You'll get an exception when you try.How will that work?
I think this will "solve" all the problems. (null is not a valid numeric value anyway.)
--Rexnull is clearly not a numeric value, but , to put an example, when dealing with domain object classes in Java that bring data from a database, somehow we need to convert this data back. The existing conversions incorrectly produce a BigDecimal(null).
On Mon, Feb 3, 2014 at 2:19 PM, Fernando Racca <fra...@gmail.com> wrote:
On Monday, 3 February 2014 21:53:59 UTC, Rex Kerr wrote:In 2.11, wrapping null in Scala's BigDecimal will not be allowed. You'll get an exception when you try.How will that work?It throws an IllegalArgumentException (IIRC) as soon as you try to create a scala.math.BigDecimal with a null value.
--
I was expecting that the implicit conversions will respect a null value if that's what the field been converted holds. Instead, it'll try to wrap it corrupting the state. Then one ends up with something worse than null, a null number wrapper object.To use Option then is not just beneficial, but mandatory whenever dealing with existing Java projects.IMHO this is a bug, and quite severe, since not only causes unexpected behaviour, but the workaround involves importing yet another implicit conversions, further polluting the code base.
scala> import java.math.{BigDecimal => JBigDecimal}
import java.math.{BigDecimal=>JBigDecimal}
scala> val x : JBigDecimal = null
x: java.math.BigDecimal = null
scala> val y : BigDecimal = null
y: BigDecimal = null
scala> val y : BigDecimal = x
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)
... 43 elided
scala> lazy val y : BigDecimal = x
y: BigDecimal = <lazy>
scala> x == y
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)
at .y$lzycompute(<console>:9)
at .y(<console>:9)
... 43 elided
scala> import java.lang.{Double => JDouble}
import java.lang.{Double=>JDouble}
scala> val e : JDouble = null
e: Double = null
scala> val f : Double = e
java.lang.NullPointerException
at scala.Predef$.Double2double(Predef.scala:352)
... 43 elided
scala> lazy val f = e
f: Double = <lazy>
scala> e == f
res2: Boolean = true
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_40).
scala> import java.math.{BigDecimal => JBigDecimal}
import java.math.{BigDecimal=>JBigDecimal}
scala> val x : JBigDecimal = null
x: java.math.BigDecimal = null
scala> val y : BigDecimal = x
java.lang.NullPointerException
at scala.math.BigDecimal.toString(BigDecimal.scala:452)
at scala.runtime.ScalaRunTime$.scala$runtime$ScalaRunTime$$inner$1(ScalaRunTime.scala:324)
at scala.runtime.ScalaRunTime$.stringOf(ScalaRunTime.scala:329)
at scala.runtime.ScalaRunTime$.replStringOf(ScalaRunTime.scala:337)
at .<init>(<console>:10)
at .<clinit>(<console>)
at $print(<console>)
scala> lazy val y : BigDecimal = x
y: BigDecimal = <lazy>
scala> x == y
java.lang.NullPointerException
at scala.math.BigDecimal.toLongExact(BigDecimal.scala:411)
at scala.math.BigDecimal$$anonfun$isValidLong$1.apply$mcV$sp(BigDecimal.scala:196)
at scala.math.BigDecimal.noArithmeticException(BigDecimal.scala:211)
at scala.math.BigDecimal.isValidLong(BigDecimal.scala:196)
at scala.math.BigDecimal.equals(BigDecimal.scala:190)
at scala.runtime.BoxesRunTime.equalsNumNum(BoxesRunTime.java:168)
at .<init>(<console>:11)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
scala> import java.lang.{Double => JDouble}
import java.lang.{Double=>JDouble}
scala> val e : JDouble = null
e: Double = null
scala> val f = e
f: Double = null
scala> e == f
res1: Boolean = true
--
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.
For more options, visit https://groups.google.com/d/optout.
You can calm down. We've already decided that wrapped nulls are a worse evil than unwrapped ones and will have the safer versions in 2.12