3 ms·
In this case the most pragmatic thing to do is to ensure nothing in your application can ever be null - use asserts during development, empty lists, null object
by Cthulhu_ 9y ago
In this case the most pragmatic thing to do is to ensure nothing in your application can ever be null - use asserts during development, empty lists, null objects, etc. Also never catch NPE's, if there is one after all those precautions, it's a developer error / bug and should be punished as such.
The problem with optionals - as Sonar will complain about - is that people will call `.get()` on an Optional without first checking `.isPresent()` for example.
Lots of things in the language that allow you to shoot yourself in the foot that other languages have solved.
- hyperpallium 9y agoSemantically, is that different from using a reference variable without first checking it !=null? Also, isn't there a static code analysis tool that checks at compile-time that reference variables annotated as @non_nullable can never be null?
- AstralStorm 9y agoThere is exactly one place where you might want to catch an NPE: top level global exception handler for logging and debugging.