bug icon indicating copy to clipboard operation
bug copied to clipboard

implicit wrappers should NPE in same way as direct call

Open scabug opened this issue 10 years ago • 3 comments

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

scabug avatar Feb 23 '15 17:02 scabug

Imported From: https://issues.scala-lang.org/browse/SI-9176?orig=1 Reporter: @adriaanm

scabug avatar Feb 23 '15 17:02 scabug

@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.

scabug avatar Feb 23 '15 20:02 scabug

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 avatar Jan 21 '22 21:01 SethTisue

@SethTisue let me know if there is a conversion of special concern

som-snytt avatar Nov 06 '23 15:11 som-snytt

There isn't. Do you think we should close the issue, as it seems unlikely that a full audit will happen?

SethTisue avatar Nov 06 '23 15:11 SethTisue

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.

som-snytt avatar Nov 06 '23 18:11 som-snytt

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

som-snytt avatar Dec 25 '23 02:12 som-snytt