bug
bug copied to clipboard
implicit wrappers should NPE in same way as direct call
Let's audit the wrappers we have in the std lib to make sure the behavior is consistent wrt a regular call on wrapped objects == null. Follow up for https://github.com/scala/scala/pull/4343
Imported From: https://issues.scala-lang.org/browse/SI-9176?orig=1 Reporter: @adriaanm
@RomanHargrave said: I think that it would make more sense to forward null on to the destination (rather than wrapping it), at least in the case of implicit conversion. If implicit conversions were to throw an exception, some developers may be a bit flummoxed on why a null pointer exception is arising from a method call that is not explicitly written in their code. That being said, if programmers are using implicit decorators for conversion, I think that it would make sense to raise an exception. I would imagine that such a behavioral split between decorators/conversion (in the cases where both are implemented) could be a little jarring in terms of codebase modifications.
example: #8232, though I haven't checked the current behavior. BigDecimal and null are a popular pair to open tickets about (#6567, #12146, #6456)
@SethTisue let me know if there is a conversion of special concern
There isn't. Do you think we should close the issue, as it seems unlikely that a full audit will happen?
I tried to go through everything with implicitConversions. I could make a spreadsheet.
An audit might consist of verifying code coverage. Someone just asked in chat how can I list all my implicits to make sure they're "necessary". For conversions, we'd like to verify that there is a documenting test case for null. How would you go about that? they asked during the interview.
Audit:
scala> import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters._
scala> val xs = null.asInstanceOf[java.util.List[Int]]
val xs: java.util.List[Int] = null
scala> xs.asScala
val res0: scala.collection.mutable.Buffer[Int] = null