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

casting a null value throws a NullPointerException #3455

Closed
DartBot opened this issue Jun 8, 2012 · 3 comments
Closed

casting a null value throws a NullPointerException #3455

DartBot opened this issue Jun 8, 2012 · 3 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Milestone

Comments

@DartBot
Copy link

DartBot commented Jun 8, 2012

This issue was originally filed by [email protected]


Per the spec on casts[1], the following code throws NullPointerException:

  var x = null;
  String s = x as String;

as does this following (type-correct) code:

  String x = null;
  String s = x as String;

This is surprising to me - null is a legal value for the String type.
It's also different to how e.g. Java and C# behave.

I can see use cases for asserting non-nullity, but this is orthogonal to casting (unless non-nullable types are added, see issue #22).

One counterargument is that the specified behaviour is consistent with 'is'.
I'm used to that inconsistency from Java (spelling it instanceof reduces the confusion there) so I'm not sure how confusing it is.

[1] http://www.dartlang.org/docs/spec/latest/dart-language-specification.html#h.4pppxtxtu3v2

@dgrove
Copy link
Contributor

dgrove commented Jun 11, 2012

Set owner to @gbracha.
Added Area-Language, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Jun 19, 2012

This comment was originally written by @tomaszkubacki


Dart shouldn't go too far from what's natural for java/c# devs

@gbracha
Copy link
Contributor

gbracha commented Jun 26, 2012

Corrected in 0.11 draft.


Added this to the M1 milestone.
Added Done label.

@DartBot DartBot added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jun 26, 2012
@DartBot DartBot added this to the M1 milestone Jun 26, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

4 participants