Null check at runtime by default + optional disabling #104677
-
Currently it is possible to run such code where we assign
The reasons I saw online for not throwing exceptions were
Wouldn't it make sense to enable runtime null check by default (generating an exception when assigning Not only that would save us from writing the boiler plate code to check if a non nullable is |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This should be moved to discussions IMHO. |
Beta Was this translation helpful? Give feedback.
-
I'm pretty sure the biggest problem with this is that NRT is optional from the beginning... meaning you can be interacting with a lot of libraries that have it turned off, even if you have it turned on yourself. This means this kind of runtime check would be unreliable at best. There are also some scenarios today that don't "respect" NRT annotations, such as some serialization-related flows (i.e. I think there is a lot more work that needs to happen before making this an automatic runtime check is feasible, but I'd also love to have it. |
Beta Was this translation helpful? Give feedback.
I'm pretty sure the biggest problem with this is that NRT is optional from the beginning... meaning you can be interacting with a lot of libraries that have it turned off, even if you have it turned on yourself.
This means this kind of runtime check would be unreliable at best.
There are also some scenarios today that don't "respect" NRT annotations, such as some serialization-related flows (i.e.
IOptions
binding), so the enforcement would not be comprehensive enough.I think there is a lot more work that needs to happen before making this an automatic runtime check is feasible, but I'd also love to have it.