Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerExcpetion on runtime in case of classOf usage #4871

Closed
scabug opened this issue Aug 4, 2011 · 5 comments
Closed

NullPointerExcpetion on runtime in case of classOf usage #4871

scabug opened this issue Aug 4, 2011 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Aug 4, 2011

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

@scabug
Copy link
Author

scabug commented Aug 4, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4871?orig=1
Reporter: @Alefas
Affected Versions: 2.9.0-1

@scabug
Copy link
Author

scabug commented Aug 4, 2011

@paulp said:
See also #1754.

@scabug
Copy link
Author

scabug commented Aug 16, 2011

@adriaanm said:
Expecting a report from Paul to further the discussion.

@scabug
Copy link
Author

scabug commented Dec 20, 2011

@paulp said:

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.

@scabug
Copy link
Author

scabug commented Dec 20, 2011

@paulp said:
Fixed in bba3b00cf7 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants