# HG changeset patch # User Christian Lins # Date 1347963510 0 # Node ID 0c16eace7b6cc08090d05130ed13b0bbe95b0092 # Parent 74f9766599b54ab60ca943a85ba1ce91c5149bf1 Add robustness checks to prevent NPEs flys-artifacts/trunk@5502 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 74f9766599b5 -r 0c16eace7b6c flys-artifacts/ChangeLog --- 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 + + * 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 Brought showarea-theme setting back (fix issue865). diff -r 74f9766599b5 -r 0c16eace7b6c flys-artifacts/src/main/java/de/intevation/flys/collections/CollectionDescriptionHelper.java --- 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(); } public void addArtifact(String uuid) { - if (artifacts == null) { - artifacts = new ArrayList(); - } - 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 : diff -r 74f9766599b5 -r 0c16eace7b6c flys-artifacts/src/main/java/de/intevation/flys/collections/FLYSArtifactCollection.java --- 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 Ingo Weinzierl */ @@ -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);