diff --git a/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/processor/util/StandardValidators.java b/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/processor/util/StandardValidators.java index 6bf9aaac33..f2ca0a1237 100644 --- a/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/processor/util/StandardValidators.java +++ b/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/processor/util/StandardValidators.java @@ -575,7 +575,12 @@ public class StandardValidators { if (input == null) { return new ValidationResult.Builder().subject(subject).input(null).explanation("List must have at least one non-empty element").valid(false).build(); } + final String[] list = input.split(","); + if (list.length == 0) { + return new ValidationResult.Builder().subject(subject).input(null).explanation("List must have at least one non-empty element").valid(false).build(); + } + for (String item : list) { String itemToValidate = trimEntries ? item.trim() : item; if (!isEmpty(itemToValidate) || !excludeEmptyEntries) { diff --git a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/validator/TestStandardValidators.java b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/validator/TestStandardValidators.java index e469955751..6c6bfe986d 100644 --- a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/validator/TestStandardValidators.java +++ b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/util/validator/TestStandardValidators.java @@ -184,6 +184,25 @@ public class TestStandardValidators { assertFalse(vr.isValid()); assertEquals(1, mockValidator.getValidateCallCount()); + // An empty list is the same as null, "" or " " + vr = val.validate("List", ",", validationContext); + assertFalse(vr.isValid()); + assertEquals(0, mockValidator.getValidateCallCount()); + + vr = val.validate("List", " , ", validationContext); + assertFalse(vr.isValid()); + assertEquals(1, mockValidator.getValidateCallCount()); + + // will evaluate to no entry + vr = val.validate("List", ",,,,", validationContext); + assertFalse(vr.isValid()); + assertEquals(0, mockValidator.getValidateCallCount()); + + // will evaluate to an empty element + vr = val.validate("List", ",foo", validationContext); + assertFalse(vr.isValid()); + assertEquals(1, mockValidator.getValidateCallCount()); + vr = val.validate("List", "1", validationContext); assertTrue(vr.isValid()); assertEquals(1, mockValidator.getValidateCallCount());