Gracefully avoiding NullPointerException in Java

I’ve always used

if ("true".equals(object.getAttribute("someAttr"))) { // ....

because although it is a little more difficult to read it’s much less verbose and I think it’s readable enough so you get used to it very easily

Leave a Comment