powered by Jive Software

Problem with getters in some classes

I noticed an issue with the way the getters are implemented in some of the classes. I first encountered it with MUCItem, but I suspect it may be an issue in other places. Basically, the getters just blindly return myXmlNode.nodeValue or myXmlNode.attributes.attr without checking myXmlNode for nullness. In some cases the same basic XMLStanza can have different child elements and attributes populated depending on the specific use case. If there is code that generically handles a message type (e.g. presence), great care must be exercise to make sure you don’t access a field unless you know for sure it will be populated. Instead of just returning null (what most people expect of a getter if the data isn’t available), an exception occurs.

Getters should check for whether the XML is present and return null if not rather than blowing up.