Scala Programming Language
  1. Scala Programming Language
  2. SI-4871

NullPointerExcpetion on runtime in case of classOf usage

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.0-1
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      object Main {
        def main(args: Array[String]) {
          class C
          val z: C = classOf.newInstance() //NPE ?!
          val n: C = classOf[Nothing].newInstance() //InstantiationException, It's ok
          val x: C = classOf[C].newInstance() //Works, It's ok
        }
      }
      

      According to specification classOf generic parameter should be C (local type inference from expected type).

        Activity

        Hide
        Paul Phillips added a comment -

        See also SI-1754.

        Show
        Paul Phillips added a comment - See also SI-1754 .
        Hide
        Adriaan Moors added a comment -

        Expecting a report from Paul to further the discussion.

        Show
        Adriaan Moors added a comment - Expecting a report from Paul to further the discussion.
        Hide
        Paul Phillips added a comment -
        scala> val z: Class[C] = classOf
        z: Class[C] = null
        
        scala> val z: Class[C] = classOf[C]
        z: Class[C] = class C
        

        I guess that sums it up.

        Show
        Paul Phillips added a comment - scala> val z: Class[C] = classOf z: Class[C] = null scala> val z: Class[C] = classOf[C] z: Class[C] = class C I guess that sums it up.
        Hide
        Paul Phillips added a comment -

        Fixed in bba3b00cf7 .

        Show
        Paul Phillips added a comment - Fixed in bba3b00cf7 .

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Alexander
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development