changeset 3436:0d63581c5df1

FLYSArtifact: Prevent NPE in getOutputForState(). Why does this happen? flys-artifacts/trunk@5099 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 23 Jul 2012 08:38:23 +0000
parents 262e7d7e58fe
children e111902834d3
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java
diffstat 2 files changed, 49 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sun Jul 22 10:38:30 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jul 23 08:38:23 2012 +0000
@@ -1,3 +1,8 @@
+2012-07-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
+	  Prevent NPE in getOutputForState(). Why does this happen?
+
 2012-07-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisCalculation.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Sun Jul 22 10:38:30 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Mon Jul 23 08:38:23 2012 +0000
@@ -1030,20 +1030,26 @@
             return outs;
         }
 
-        logger.debug("Filter Facets with " + filterFacets.size() + " filters.");
+        boolean debug = logger.isDebugEnabled();
+
+        if (debug) {
+            logger.debug(
+                "Filter Facets with " + filterFacets.size() + " filters.");
+        }
 
         List<Output> filtered = new ArrayList<Output>();
 
         for (Output out: outs) {
             String outName = out.getName();
 
-            logger.debug("  filter Facets for Output: " + outName);
+            if (debug) {
+                logger.debug("  filter Facets for Output: " + outName);
+            }
 
             List<Facet> fFacets = filterFacets.get(outName);
             if (fFacets != null) {
-                logger.debug("" + fFacets.size() + " filters for: " + outName);
-
-                if (logger.isDebugEnabled()) {
+                if (debug) {
+                    logger.debug("" + fFacets.size() + " filters for: " + outName);
                     for (Facet tmp: fFacets) {
                         logger.debug("   filter = '" + tmp.getName() + "'");
                     }
@@ -1061,7 +1067,10 @@
                     }
                 }
 
-                logger.debug("Facets after filtering = " + resultFacets.size());
+                if (debug) {
+                    logger.debug(
+                        "Facets after filtering = " + resultFacets.size());
+                }
 
                 if (!resultFacets.isEmpty()) {
                     DefaultOutput nout = new DefaultOutput(
@@ -1074,7 +1083,9 @@
             }
         }
 
-        logger.debug("All Facets after filtering = " + filtered.size());
+        if (debug) {
+            logger.debug("All Facets after filtering = " + filtered.size());
+        }
 
         return filtered;
     }
@@ -1087,7 +1098,9 @@
      * @return list of outputs
      */
     public List<Output> getOutputs(Object context) {
-        logger.debug("##### Get Outputs for: " + identifier() + " #####");
+        if (logger.isDebugEnabled()) {
+            logger.debug("##### Get Outputs for: " + identifier() + " #####");
+        }
 
         dumpArtifact();
 
@@ -1129,11 +1142,23 @@
      * @return list of output(s) for given state.
      */
     protected List<Output> getOutputForState(DefaultState state) {
-        logger.debug("Find Outputs for State: " + state.getID());
+
+        if (state == null) {
+            logger.error("state == null: This should not happen!");
+            return new ArrayList<Output>();
+        }
+
+        boolean debug = logger.isDebugEnabled();
+
+        if (debug) {
+            logger.debug("Find Outputs for State: " + state.getID());
+        }
 
         List<Output> list = state.getOutputs();
         if (list == null || list.size() == 0) {
-            logger.debug("-> No output modes for this state.");
+            if (debug) {
+                logger.debug("-> No output modes for this state.");
+            }
             return new ArrayList<Output>();
         }
 
@@ -1142,13 +1167,17 @@
         List<Facet> fs = facets.get(stateId);
 
         if (fs == null || fs.size() == 0) {
-            logger.debug("No facets found.");
+            if (debug) {
+                logger.debug("No facets found.");
+            }
             return new ArrayList<Output>();
         }
 
         List<Output> gen = generateOutputs(list, fs);
 
-        logger.debug("State '" + stateId + "' has " + gen.size() + " outs");
+        if (debug) {
+            logger.debug("State '" + stateId + "' has " + gen.size() + " outs");
+        }
 
         return gen;
     }
@@ -1434,7 +1463,9 @@
      */
     @Override
     public void endOfLife(Object context) {
-        logger.info("FLYSArtifact.endOfLife: " + identifier());
+        if (logger.isDebugEnabled()) {
+            logger.debug("FLYSArtifact.endOfLife: " + identifier());
+        }
 
         ArrayList<String> ids       = (ArrayList<String>) getPreviousStateIds();
         ArrayList<String> toDestroy = (ArrayList<String>) ids.clone();

http://dive4elements.wald.intevation.org