]> git.basschouten.com Git - openhab-addons.git/commitdiff
[astro] Correcting some SAT finding and a blocking point (#8964)
authorGaël L'hopital <gael@lhopital.org>
Sun, 8 Nov 2020 20:09:08 +0000 (21:09 +0100)
committerGitHub <noreply@github.com>
Sun, 8 Nov 2020 20:09:08 +0000 (12:09 -0800)
Signed-off-by: clinique <gael@lhopital.org>
bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/MoonCalc.java
bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/calc/SunZodiacCalc.java
bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/handler/SunHandler.java
bundles/org.openhab.binding.astro/src/main/java/org/openhab/binding/astro/internal/util/PropertyUtils.java

index bd9f345453ba4a5f16856f243e824b62be5e5067..188bba4456f8e55d8ad858d5a6504d5aa6aa72d5 100644 (file)
@@ -13,6 +13,7 @@
 package org.openhab.binding.astro.internal.calc;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.Calendar;
 
 import org.openhab.binding.astro.internal.model.Eclipse;
@@ -233,7 +234,7 @@ public class MoonCalc {
         rounded = Math.floor(rounded) + riseMinute;
 
         BigDecimal bd = new BigDecimal(Double.toString(rounded));
-        bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
+        bd = bd.setScale(2, RoundingMode.HALF_UP);
         return bd.doubleValue();
     }
 
index 454e917145198dad6cf62fddcd090f856c5b5466..729440c4b80e25a978af727015fc479c8fa5fd27 100644 (file)
@@ -49,7 +49,7 @@ public class SunZodiacCalc {
             zodiacsByYear.put(year, zodiacs);
         }
 
-        return zodiacs.stream().filter(z -> z.isValid(calendar)).findFirst();
+        return zodiacs != null ? zodiacs.stream().filter(z -> z.isValid(calendar)).findFirst() : Optional.empty();
     }
 
     /**
index 0c6ae90e5bd30f4a1bd8b9c8478d92c005178047..80d11b038d12d7e726d3422ffdd236351686e537 100644 (file)
@@ -105,8 +105,12 @@ public class SunHandler extends AstroThingHandler {
 
     public @Nullable ZonedDateTime getEventTime(SunPhaseName sunPhase, ZonedDateTime date, boolean begin) {
         Range eventRange = getSunAt(date).getAllRanges().get(sunPhase);
-        Calendar cal = begin ? eventRange.getStart() : eventRange.getEnd();
-        return ZonedDateTime.ofInstant(cal.toInstant(), date.getZone());
+        if (eventRange != null) {
+            Calendar cal = begin ? eventRange.getStart() : eventRange.getEnd();
+            return ZonedDateTime.ofInstant(cal.toInstant(), date.getZone());
+        } else {
+            return null;
+        }
     }
 
     @Override
index 41dc016d5a7bac30e9fc0500488c5814edade3a5..e2cf730ffe095916812225c5308956ad2ddb3db0 100644 (file)
@@ -91,7 +91,11 @@ public class PropertyUtils {
         Method m = instance.getClass().getMethod(toGetterString(propertyName), null);
         Object result = m.invoke(instance, (Object[]) null);
         if (nestedIndex + 1 < properties.length) {
-            return getPropertyValue(result, properties, nestedIndex + 1);
+            if (result != null) {
+                return getPropertyValue(result, properties, nestedIndex + 1);
+            } else {
+                throw new NullPointerException();
+            }
         }
         return result;
     }