Skip to content

Commit 63cfd5b

Browse files
committed
JAVA-2335: Null value in ServerAddress list should cause an IllegalArgumentException expection rather than a NullPointerException
1 parent 9bd5085 commit 63cfd5b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

driver-core/src/main/com/mongodb/connection/ClusterSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public Builder hosts(final List<ServerAddress> hosts) {
102102
}
103103
Set<ServerAddress> hostsSet = new LinkedHashSet<ServerAddress>(hosts.size());
104104
for (ServerAddress host : hosts) {
105+
notNull("host", host);
105106
hostsSet.add(new ServerAddress(host.getHost(), host.getPort()));
106107
}
107108
this.hosts = Collections.unmodifiableList(new ArrayList<ServerAddress>(hostsSet));

driver-core/src/test/unit/com/mongodb/connection/ClusterSettingsSpecification.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ class ClusterSettingsSpecification extends Specification {
213213
thrown(IllegalArgumentException)
214214
}
215215

216+
def 'should throws if hosts list contains null value'() {
217+
when:
218+
ClusterSettings.builder().hosts([null]).build();
219+
220+
then:
221+
thrown(IllegalArgumentException)
222+
}
223+
216224
def 'should remove duplicate hosts'() {
217225
when:
218226
def settings = ClusterSettings.builder().hosts([new ServerAddress('server1'),

0 commit comments

Comments
 (0)