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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 4, 2011

@paulp said:
See also #1754.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Aug 16, 2011

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

@scabug

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Author

@scabug scabug commented Dec 20, 2011

@paulp said:
Fixed in bba3b00cf7 .

@scabug scabug closed this Dec 20, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.