When I first moved from c to Java I thought that I've finished will all the annoying parameter checks in the begining of every function . (Blessed exceptions)
Lately I've realized that I'm slowly moving back to that practice again , and I'm starting to get really annoyed with all the
if (null == a || null == b || null == a.getValue() || ...)
{
return null;
}
For example , I have a utility class that analyses web pages and extract specific elements from them. Any call to dom object function with null elements usually results in an exception - So in almost any function I write in this class has countless null checks :
private URL extractUrl(Element element) throws Exception {
if (null == element) {
return null;
} ...
public List<Object> getConcreteElements(String xpath) throws Exception {
if (null == xpath) {
return Collections.emptyList();
}...
public String getElementsAsXML(String xpath) throws Exception {
if (null == xpath) {
return null;
}...
in the beginning of every function. Is this something I should get used too or is there some coding practice I'm unaware of that can simplify my life?