Mercurial > dive4elements > river
changeset 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 | 74f9766599b5 |
children | a65eb6d44122 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionDescriptionHelper.java flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java |
diffstat | 3 files changed, 40 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Sep 18 09:49:45 2012 +0000 +++ b/flys-artifacts/ChangeLog Tue Sep 18 10:18:30 2012 +0000 @@ -1,3 +1,9 @@ +2012-09-18 Christian Lins <christian.lins@intevation.de> + + * src/main/java/de/intevation/flys/collections/CollectionDescriptionHelper.java, + src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java: + Add robustness checks to prevent NPEs (#859). + 2012-09-18 Felix Wolfsteller <felix.wolfsteller@intevation.de> Brought showarea-theme setting back (fix issue865).
--- 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 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Tue Sep 18 09:49:45 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java Tue Sep 18 10:18:30 2012 +0000 @@ -1,5 +1,21 @@ package de.intevation.flys.collections; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +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 de.intevation.artifactdatabase.Backend; import de.intevation.artifactdatabase.Backend.PersistentArtifact; import de.intevation.artifactdatabase.DefaultArtifactCollection; @@ -19,22 +35,6 @@ import de.intevation.flys.exports.OutputHelper; import de.intevation.flys.utils.FLYSUtils; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -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; - /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ @@ -126,6 +126,11 @@ CollectionAttribute cAttribute = buildOutAttributes(db, context, oldParser, uuids); + if (cAttribute == null) { + log.warn("mergeAttributes: cAttribute == null"); + return null; + } + cAttribute.setLoadedRecommendations( getLoadedRecommendations(oldParser.getAttributeDocument())); @@ -450,8 +455,6 @@ AttributeParser aParser, String[] uuids) { - Document doc = XMLUtils.newDocument(); - FLYSContext flysContext = FLYSUtils.getFlysContext(context); StateEngine engine = (StateEngine) flysContext.get( FLYSContext.STATE_ENGINE_KEY);