Someone has developed code based on complete data; XML has always had every element. The data source now sends sparse XML; if he was empty before that, he went missing. So, it's time to refactor when fixing bugs.
There are over 100 lines of code:
functionDoSomething(foo, bar, getRoot().getChild("1").getChild("A"). getChild("oo").getContent());
Except now, getChild ("A") can return null. Or any of the getChild (xxx) methods could.
As another turn, instead of getChild (), there are actually four separate methods that can only be executed in specific orders. Someone suggested calling varargs, which is a good idea, but will not work as we would like.
What is the fastest way to clear this? Best? A βtry / catchβ around each line was suggested, but the person, this one is ugly. By destroying the third argument to the aforementioned method, it can work its own function ... but it will entail more than 100 new methods that seem ugly, albeit less.
The number of calls to getChild (xxx) is six to ten per line without a fixed depth. There is also no way to get the correct DTD for this; things will be added later without previous headings, and where I would prefer a warning in the logs when this happens, additional lines in XML should be handled gracefully.
Ideas?
getChild () is a convenience method, in fact. The cleanest way that I mean is for convenience methods to return a valid Child object, but having this "empty" Child getContent () always returns "".