Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionDescriptionHelper.java @ 3870:0c16eace7b6c
Add robustness checks to prevent NPEs
flys-artifacts/trunk@5502 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Tue, 18 Sep 2012 10:18:30 +0000 |
parents | 4a76da133144 |
children |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionDescriptionHelper.java Tue Sep 18 09:49:45 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionDescriptionHelper.java Tue Sep 18 10:18:30 2012 +0000 @@ -6,18 +6,16 @@ import javax.xml.xpath.XPathConstants; +import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.apache.log4j.Logger; - import de.intevation.artifacts.ArtifactDatabase; import de.intevation.artifacts.ArtifactDatabaseException; import de.intevation.artifacts.ArtifactNamespaceContext; import de.intevation.artifacts.CallContext; - import de.intevation.artifacts.common.utils.XMLUtils; import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; @@ -63,20 +61,17 @@ long ttl, CallContext callContext ) { - this.name = name; - this.uuid = uuid; - this.creation = creation; - this.ttl = ttl; - this.context = callContext; - this.database = callContext.getDatabase(); + this.name = name; + this.uuid = uuid; + this.creation = creation; + this.ttl = ttl; + this.context = callContext; + this.database = callContext.getDatabase(); + this.artifacts = new ArrayList<String>(); } public void addArtifact(String uuid) { - if (artifacts == null) { - artifacts = new ArrayList<String>(); - } - if (uuid != null && uuid.length() > 0) { artifacts.add(uuid); } @@ -197,10 +192,12 @@ protected void appendAttribute(Element root) { - Document owner = root.getOwnerDocument(); - Document attr = attribute.toXML(); + if (attribute != null) { + Document owner = root.getOwnerDocument(); + Document attr = attribute.toXML(); - root.appendChild(owner.importNode(attr.getFirstChild(), true)); + root.appendChild(owner.importNode(attr.getFirstChild(), true)); + } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :