From 200a45d66f17c0b33f427ec3646263583907466c Mon Sep 17 00:00:00 2001 From: RyanHealey Date: Fri, 13 Jan 2023 16:52:15 +0000 Subject: [PATCH] fix null pointer exception for hasValue in a repeating group when there is no value --- .../java/com/lmax/simpledsl/internal/RepeatingParamValues.java | 3 ++- .../com/lmax/simpledsl/internal/RepeatingParamValuesTest.java | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/lmax/simpledsl/internal/RepeatingParamValues.java b/src/main/java/com/lmax/simpledsl/internal/RepeatingParamValues.java index 6f813ce..303e142 100644 --- a/src/main/java/com/lmax/simpledsl/internal/RepeatingParamValues.java +++ b/src/main/java/com/lmax/simpledsl/internal/RepeatingParamValues.java @@ -22,7 +22,8 @@ class RepeatingParamValues implements RepeatingGroup @Override public boolean hasValue(final String name) { - return !getValues(name).isEmpty(); + final List values = getValues(name); + return !(values == null || values.isEmpty()); } diff --git a/src/test/java/com/lmax/simpledsl/internal/RepeatingParamValuesTest.java b/src/test/java/com/lmax/simpledsl/internal/RepeatingParamValuesTest.java index c5fabdf..abd38d8 100644 --- a/src/test/java/com/lmax/simpledsl/internal/RepeatingParamValuesTest.java +++ b/src/test/java/com/lmax/simpledsl/internal/RepeatingParamValuesTest.java @@ -27,7 +27,6 @@ import java.util.Map; import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -113,7 +112,6 @@ public void shouldNotReportOptionalValueAsPresentWhenNoValueProvided() final OptionalArg otherArg = new OptionalArg("bar"); final Map> values = new HashMap<>(); values.put("foo", Collections.singletonList("abc")); - values.put("bar", emptyList()); final RepeatingParamValues params = new RepeatingParamValues(asList(requiredArg, otherArg).toArray(new DslArg[0]), values); assertFalse(params.hasValue("bar"));