Consider this line:
if (object.getAttribute(\"someAttr\").equals(\"true\")) { // ....
Obviously this line is a potential bug, the attribute
In the second option, you can take advantage of short-circuiting &&:
&&
String attr = object.getAttribute("someAttr"); if (attr != null && attr.equals("true")) { // ....