Repository: kafka Updated Branches: refs/heads/trunk 1af096039 -> e3892c29c
MINOR: Handle nulls in NonEmptyListValidator Author: Ewen Cheslack-Postava <[email protected]> Reviewers: Ismael Juma <[email protected]> Closes #3045 from ewencp/minor-non-empty-list-validator-nulls Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/e3892c29 Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/e3892c29 Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/e3892c29 Branch: refs/heads/trunk Commit: e3892c29c342629be789437c2c52b4e367af52ef Parents: 1af0960 Author: Ewen Cheslack-Postava <[email protected]> Authored: Sun May 14 18:33:05 2017 +0100 Committer: Ismael Juma <[email protected]> Committed: Sun May 14 18:33:05 2017 +0100 ---------------------------------------------------------------------- .../transforms/util/NonEmptyListValidator.java | 2 +- .../util/NonEmptyListValidatorTest.java | 40 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/e3892c29/connect/transforms/src/main/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidator.java ---------------------------------------------------------------------- diff --git a/connect/transforms/src/main/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidator.java b/connect/transforms/src/main/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidator.java index 390812f..dacb07b 100644 --- a/connect/transforms/src/main/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidator.java +++ b/connect/transforms/src/main/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidator.java @@ -25,7 +25,7 @@ public class NonEmptyListValidator implements ConfigDef.Validator { @Override public void ensureValid(String name, Object value) { - if (((List) value).isEmpty()) { + if (value == null || ((List) value).isEmpty()) { throw new ConfigException(name, value, "Empty list"); } } http://git-wip-us.apache.org/repos/asf/kafka/blob/e3892c29/connect/transforms/src/test/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidatorTest.java ---------------------------------------------------------------------- diff --git a/connect/transforms/src/test/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidatorTest.java b/connect/transforms/src/test/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidatorTest.java new file mode 100644 index 0000000..f7d4f43 --- /dev/null +++ b/connect/transforms/src/test/java/org/apache/kafka/connect/transforms/util/NonEmptyListValidatorTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.kafka.connect.transforms.util; + +import org.apache.kafka.common.config.ConfigException; +import org.junit.Test; + +import java.util.Collections; + +public class NonEmptyListValidatorTest { + + @Test(expected = ConfigException.class) + public void testNullList() { + new NonEmptyListValidator().ensureValid("foo", null); + } + + @Test(expected = ConfigException.class) + public void testEmptyList() { + new NonEmptyListValidator().ensureValid("foo", Collections.emptyList()); + } + + @Test + public void testValidList() { + new NonEmptyListValidator().ensureValid("foo", Collections.singletonList("foo")); + } +}
