changeset 3745:e86cd5176678

Check to prevent NPE flys-artifacts/trunk@5429 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Mon, 10 Sep 2012 20:32:39 +0000
parents b220287a171e
children 7bc61f4ab26b
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeTimerangeState.java
diffstat 2 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Sep 10 16:52:15 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Sep 10 20:32:39 2012 +0000
@@ -1,3 +1,8 @@
+2012-09-10	Christian Lins	<christian.lins@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/states/GaugeTimerangeState.java:
+	  Add additional check to prevent NPE (fix for #844)
+
 2012-09-10	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/RangeWithValues.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeTimerangeState.java	Mon Sep 10 16:52:15 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeTimerangeState.java	Mon Sep 10 20:32:39 2012 +0000
@@ -4,15 +4,13 @@
 import java.util.List;
 
 import org.apache.log4j.Logger;
-
+import org.hibernate.SQLQuery;
 import org.hibernate.Session;
-import org.hibernate.SQLQuery;
 import org.hibernate.type.StandardBasicTypes;
 
-import de.intevation.flys.model.Gauge;
+import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.backend.SessionHolder;
-
-import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.model.Gauge;
 import de.intevation.flys.utils.FLYSUtils;
 
 
@@ -22,7 +20,7 @@
 public class GaugeTimerangeState extends IntRangeState {
 
     private static final Logger logger =
-        Logger.getLogger(GaugeTimerangeState.class);
+            Logger.getLogger(GaugeTimerangeState.class);
 
 
     protected int[] getLowerUpper(FLYSArtifact flys) {
@@ -36,17 +34,17 @@
         Session session = SessionHolder.HOLDER.get();
 
         SQLQuery query = session.createSQLQuery(
-            "SELECT min(start_time) as min, max(stop_time) as max " +
-            "FROM time_intervals WHERE id in " +
-            "(SELECT time_interval_id FROM discharge_tables " +
-            "WHERE gauge_id =:gid)");
+                "SELECT min(start_time) as min, max(stop_time) as max " +
+                        "FROM time_intervals WHERE id in " +
+                        "(SELECT time_interval_id FROM discharge_tables " +
+                "WHERE gauge_id =:gid)");
 
         query.addScalar("min", StandardBasicTypes.CALENDAR);
         query.addScalar("max", StandardBasicTypes.CALENDAR);
 
         query.setInteger("gid", gauge.getId());
 
-        List results = query.list();
+        List<?> results = query.list();
 
         if (results != null) {
             Object[] res = (Object[]) results.get(0);
@@ -54,7 +52,9 @@
             Calendar lo = (Calendar) res[0];
             Calendar up = (Calendar) res[1];
 
-            return new int[] { lo.get(Calendar.YEAR), up.get(Calendar.YEAR) };
+            if (lo != null && up != null) {
+                return new int[] { lo.get(Calendar.YEAR), up.get(Calendar.YEAR) };
+            }
         }
 
         logger.warn("Could not determine time range for gauge: " + gauge);

http://dive4elements.wald.intevation.org