3 ms·
A lot of those NullExceptions (and a lot of boilerplate code) could be linted away if Java gave compiler-level semantics to @NotNull annotations. Letting null
by paulmd 8y ago
A lot of those NullExceptions (and a lot of boilerplate code) could be linted away if Java gave compiler-level semantics to @NotNull annotations.
Letting null values propagate through your program is frequently a code smell, you want to constrain it at the boundaries of your program logic if possible. Unfortunately, Java does not have a semantic way to do this, just documentation and discipline.
- mrighele 8y agoChecker framework [1] can be used to add compile time checks on such annotations. Unfortunately I found it non trivial to setup (that was some time ago though, I'll have to check again). I noticed also that a recent version of Wildfly application server can do those check at runtime, but I haven't investigated it enough to see if it is configurable and the performance impact of the checks [1] https://checkerframework.org https://checkerframework.org
- joe_fishfish 8y agoKotlin is amazing for this.
- pron 8y agoAs Java supports pluggable type systems, this can be achieved by one: https://checkerframework.org/manual/#nullness-checker https://checkerframework.org/manual/#nullness-checker