[PATCH 1 of 2] Avoid some annoying NPEs when developing with sparsely filled database

Wald Commits scm-commit at wald.intevation.org
Tue May 9 18:45:02 CEST 2017


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1494345490 -7200
# Node ID c4ce250939539cc1c8d977a2c0220138eee2e606
# Parent  19fa9fc39fa272d54cd9fdb4d7f5dae5bdea4ca3
Avoid some annoying NPEs when developing with sparsely filled database.

diff -r 19fa9fc39fa2 -r c4ce25093953 artifacts/src/main/java/org/dive4elements/river/artifacts/services/RiverInfoService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/RiverInfoService.java	Tue May 09 16:05:42 2017 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/RiverInfoService.java	Tue May 09 17:58:10 2017 +0200
@@ -64,17 +64,20 @@
 
         double[] minmax  = river.determineMinMaxDistance();
         double[] minmaxq = river.determineMinMaxQ();
+        Long offnumber = river.getOfficialNumber();
 
         Element r = ec.create("river");
         ec.addAttr(r, "name", river.getName(), true);
-        ec.addAttr(r, "start", Double.toString(minmax[0]), true);
-        ec.addAttr(r, "end", Double.toString(minmax[1]), true);
+        ec.addAttr(r, "start",
+            minmax != null ? Double.toString(minmax[0]) : "", true);
+        ec.addAttr(r, "end",
+            minmax != null ? Double.toString(minmax[1]) : "", true);
         ec.addAttr(r, "wstunit", river.getWstUnit().getName(), true);
         ec.addAttr(r, "kmup", Boolean.toString(river.getKmUp()), true);
         ec.addAttr(r, "minq", Double.toString(minmaxq[0]), true);
         ec.addAttr(r, "maxq", Double.toString(minmaxq[1]), true);
-        ec.addAttr(r, "official", Long.toString(river.getOfficialNumber()),
-                    true);
+        ec.addAttr(r, "official",
+            offnumber != null ? Long.toString(offnumber) : "", true);
         ec.addAttr(r, "model-uuid", river.getModelUuid(), true);
 
         riverele.appendChild(r);
diff -r 19fa9fc39fa2 -r c4ce25093953 backend/src/main/java/org/dive4elements/river/model/River.java
--- a/backend/src/main/java/org/dive4elements/river/model/River.java	Tue May 09 16:05:42 2017 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/River.java	Tue May 09 17:58:10 2017 +0200
@@ -393,8 +393,10 @@
 
         if (!result.isEmpty()) {
             Object[] minMax = result.get(0);
-            return new double[] { ((BigDecimal)minMax[0]).doubleValue(),
-                ((BigDecimal)minMax[1]).doubleValue() };
+            if (minMax[0] != null && minMax[1] != null) {
+                return new double[] { ((BigDecimal)minMax[0]).doubleValue(),
+                    ((BigDecimal)minMax[1]).doubleValue() };
+            }
         }
 
         return null;


More information about the Dive4Elements-commits mailing list