And yet they're the easiest exceptions to avoid. It's actually pretty much programming 101: 1) don't return null, and/or 2) check to make sure it's not null before you do something that can throw an NPE.
var element = null;
element.getAttribute("id");
// crash
Sure. My point is that if you do something really dumb, then the compiler/parser should be able to stop you and warn you until it's too late. When you fix this bug for 1000th time it's not funny anymore. It's often not your own code.
Unit testing is a possible approach, but I don't quite see how it's better than a simple "if (x != null)" check (you need it anyway probably). When adding such a test you need to think about it yourself upfront. This test certainly reassures that it's not null, and helps with regressions. You could also add assertions/preconditions for that matter.
IntelliJ is great, I use it all the time, but in its core it is only as good as the language itself (maybe a little bit better).
-4
u/yogazook Jun 28 '16
And yet they're the easiest exceptions to avoid. It's actually pretty much programming 101: 1) don't return null, and/or 2) check to make sure it's not null before you do something that can throw an NPE.
Yeah, no shit.