lkokhreidze commented on a change in pull request #11837: URL: https://github.com/apache/kafka/pull/11837#discussion_r826828584
########## File path: clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java ########## @@ -1121,6 +1121,27 @@ public String toString() { } } + public static class ListSize implements Validator { + final int maxSize; + + private ListSize(final int maxSize) { + this.maxSize = maxSize; + } + + public static ListSize atMostOfSize(final int maxSize) { + return new ListSize(maxSize); + } + + @Override + public void ensureValid(final String name, final Object value) { + @SuppressWarnings("unchecked") + List<String> values = (List<String>) value; + if (values.size() > maxSize) { + throw new ConfigException(name, value, "exceeds maximum list size of [" + maxSize + "]."); Review comment: It should output list of strings. Added test to verify. ########## File path: clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java ########## @@ -722,4 +724,35 @@ public void testNiceTimeUnits() { assertEquals(" (365 days)", ConfigDef.niceTimeUnits(Duration.ofDays(365).toMillis())); } + @Test + public void testThrowsExceptionWhenListSizeExceedsLimit() { + assertThrows(ConfigException.class, () -> new ConfigDef().define("lst", + Type.LIST, + asList("a", "b"), + ListSize.atMostOfSize(1), + Importance.HIGH, + "lst doc")); + } + + @Test + public void testNoExceptionIsThrownWhenListSizeEqualsTheLimit() { + final List<String> lst = asList("a", "b", "c"); + new ConfigDef().define("lst", Review comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org