changeset 1623:0221451a24fe

Guard access to dataset to avoid NullPointerException. flys-artifacts/trunk@2798 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 21 Sep 2011 12:55:36 +0000
parents 6d0299d63819
children 238145ef67da
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 2 files changed, 25 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Sep 21 10:08:47 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Sep 21 12:55:36 2011 +0000
@@ -1,3 +1,10 @@
+2011-09-21  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+ Avoid NullPointerException when drawing XYChart without data.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  Guard calls to dataset to avoid NullPointerException.
+
 2011-09-21  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue325 (FLYS Client: Auswahl des DGM zeigt numerischen Wert an)
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Wed Sep 21 10:08:47 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Wed Sep 21 12:55:36 2011 +0000
@@ -256,23 +256,25 @@
         double[] xr = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
         double[] yr = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
 
-        int sCount = dataset.getSeriesCount();
-
-        for (int i = 0; i < sCount; i++) {
-            int iCount = dataset.getItemCount(i);
+        if (dataset != null) {
+            int sCount = dataset.getSeriesCount();
 
-            for (int j = 0; j < iCount; j++) {
-                double x = dataset.getX(i, j).doubleValue();
-                double y = dataset.getY(i, j).doubleValue();
-
-                if (!Double.isNaN(x)) {
-                    xr[0] = xr[0] < x ? xr[0] : x;
-                    xr[1] = xr[1] > x ? xr[1] : x;
-                }
-
-                if (!Double.isNaN(y)) {
-                    yr[0] = yr[0] < y ? yr[0] : y;
-                    yr[1] = yr[1] > y ? yr[1] : y;
+            for (int i = 0; i < sCount; i++) {
+                int iCount = dataset.getItemCount(i);
+    
+                for (int j = 0; j < iCount; j++) {
+                    double x = dataset.getX(i, j).doubleValue();
+                    double y = dataset.getY(i, j).doubleValue();
+    
+                    if (!Double.isNaN(x)) {
+                        xr[0] = xr[0] < x ? xr[0] : x;
+                        xr[1] = xr[1] > x ? xr[1] : x;
+                    }
+    
+                    if (!Double.isNaN(y)) {
+                        yr[0] = yr[0] < y ? yr[0] : y;
+                        yr[1] = yr[1] > y ? yr[1] : y;
+                    }
                 }
             }
         }

http://dive4elements.wald.intevation.org