From 7f695fe6f0a9d85dcdfef9a1224052adcb4685fe Mon Sep 17 00:00:00 2001 From: Octavian Patrascoiu Date: Tue, 10 Sep 2024 13:23:18 +0100 Subject: [PATCH] Improve reliability --- .../gs/dmn/feel/lib/type/time/xml/DefaultDurationType.java | 6 ++++++ dmn-runtime/src/main/java/com/gs/dmn/runtime/Context.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dmn-runtime/src/main/java/com/gs/dmn/feel/lib/type/time/xml/DefaultDurationType.java b/dmn-runtime/src/main/java/com/gs/dmn/feel/lib/type/time/xml/DefaultDurationType.java index cae5eca54..e02e0a359 100644 --- a/dmn-runtime/src/main/java/com/gs/dmn/feel/lib/type/time/xml/DefaultDurationType.java +++ b/dmn-runtime/src/main/java/com/gs/dmn/feel/lib/type/time/xml/DefaultDurationType.java @@ -94,10 +94,16 @@ public Duration durationDivideNumber(Duration first, BigDecimal second) { if (isYearsAndMonthsDuration(first)) { Long firstValue = monthsValue(first); BigDecimal months = divideNumbers(firstValue, second); + if (months == null) { + throw new DMNRuntimeException(String.format("Cannot divide '%s' by '%s'", first, second)); + } return XMLDurationFactory.INSTANCE.yearMonthFromValue(months.longValue()); } else if (isDaysAndTimeDuration(first)) { Long firstValue = secondsValue(first); BigDecimal seconds = divideNumbers(firstValue, second); + if (seconds == null) { + throw new DMNRuntimeException(String.format("Cannot divide '%s' by '%s'", first, second)); + } return XMLDurationFactory.INSTANCE.dayTimeFromValue(seconds.longValue()); } else { throw new DMNRuntimeException(String.format("Cannot divide '%s' by '%s'", first, second)); diff --git a/dmn-runtime/src/main/java/com/gs/dmn/runtime/Context.java b/dmn-runtime/src/main/java/com/gs/dmn/runtime/Context.java index 432784b26..e974cfe64 100644 --- a/dmn-runtime/src/main/java/com/gs/dmn/runtime/Context.java +++ b/dmn-runtime/src/main/java/com/gs/dmn/runtime/Context.java @@ -85,7 +85,7 @@ public String toString() { Set set = this.map.keySet(); if (set != null && !set.isEmpty() && set.iterator().next() instanceof String) { ArrayList orderedKeys = new ArrayList<>(set); - Collections.sort(orderedKeys, (s1, s2) -> s1 != null && s2 != null ? s1.compareTo(s1) : -1); + orderedKeys.sort((s1, s2) -> s1 != null && s2 != null ? s1.compareTo(s2) : -1); StringBuilder result = new StringBuilder("{"); for(int i=0; i