Aladdin - Scala Bugtracking
[#162] project: specification priority: high category: bug
submitter assigned to status date submitted
Burak Martin fixed 2003-09-30 13:04:31.0
subject handling of null-expression
code
object bug {
  def main(args:Array[String]):Unit = {
    var ch = null.asInstanceOf[char];
  }
}
what happened
/tmp> scalac bug.scala
/tmp> java bug
Exception in thread "main" java.lang.NullPointerException
	at bug$.main(bug.scala:4)
	at bug.main(bug.scala)
what expected according to the spec (p.47), cast should do nothing. Hence running the program must not result in an NullPointerException.
[back to overview]
Changes of this bug report
Michel  edited on  2003-09-30 13:58:33.0
The specification should say what to do when, like here, we try to cast null to a value type. Should we raise a null pointer exception, like here? Or raise a ClassCastException? Or return the "zero" for the given type?

The current specification says "asInstanceOf[T] always returns the null object itself" (when applied on the null object) but this is clearly not an option here, as null cannot be stored in a value of type char).

Martin  edited on  2003-10-06 10:31:34.0
I have changed the spec as follows:

\lstinline@asInstanceOf[$T\,$]@ returns the ``null'' object itself if $T$ conforms to \lstinline@scala.AnyRef@, and throws a \lstinline@NullPointerExcetpion@ otherwise.