Skip to content

Commit 4f54484

Browse files
authored
adding a null check when validating list of urls (#466)
1 parent 831aefb commit 4f54484

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/java/io/confluent/connect/elasticsearch/ElasticsearchSinkConnectorConfig.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,13 @@ private Map<String, String> parseMapConfig(List<String> values) {
609609
private static class UrlListValidator implements Validator {
610610

611611
@Override
612+
@SuppressWarnings("unchecked")
612613
public void ensureValid(String name, Object value) {
613-
@SuppressWarnings("unchecked")
614+
if (value == null) {
615+
throw new ConfigException(
616+
name, value, "The provided url list is null."
617+
);
618+
}
614619
List<String> urls = (List<String>) value;
615620
for (String url : urls) {
616621
try {

src/test/java/io/confluent/connect/elasticsearch/ElasticsearchSinkConnectorConfigTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import static io.confluent.connect.elasticsearch.ElasticsearchSinkConnectorConfig.TYPE_NAME_CONFIG;
88
import static org.junit.Assert.assertEquals;
99

10+
import org.apache.kafka.common.config.ConfigException;
1011
import org.junit.Before;
1112
import org.junit.Test;
1213

@@ -40,4 +41,10 @@ public void testSetHttpTimeoutsConfig() {
4041
assertEquals(config.readTimeoutMs(), 10000);
4142
assertEquals(config.connectionTimeoutMs(), 15000);
4243
}
44+
45+
@Test(expected = ConfigException.class)
46+
public void shouldNotAllowNullUrlList(){
47+
props.put(CONNECTION_URL_CONFIG, null);
48+
new ElasticsearchSinkConnectorConfig(props);
49+
}
4350
}

0 commit comments

Comments
 (0)