Skip to content

Commit 174680b

Browse files
committed
Guard RedisClusterConfiguration.asMap and RedisSentinelConfiguration.asMap with Assert.noNullElements(…).
Closes #2167
1 parent 0691ffd commit 174680b

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/main/java/org/springframework/data/redis/connection/RedisClusterConfiguration.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.redis.connection;
1717

18-
import static org.springframework.util.Assert.*;
1918
import static org.springframework.util.StringUtils.*;
2019

2120
import java.util.Collection;
@@ -91,7 +90,7 @@ public RedisClusterConfiguration(Collection<String> clusterNodes) {
9190
*/
9291
public RedisClusterConfiguration(PropertySource<?> propertySource) {
9392

94-
notNull(propertySource, "PropertySource must not be null!");
93+
Assert.notNull(propertySource, "PropertySource must not be null!");
9594

9695
this.clusterNodes = new LinkedHashSet<>();
9796

@@ -112,7 +111,7 @@ public RedisClusterConfiguration(PropertySource<?> propertySource) {
112111
*/
113112
public void setClusterNodes(Iterable<RedisNode> nodes) {
114113

115-
notNull(nodes, "Cannot set cluster nodes to 'null'.");
114+
Assert.notNull(nodes, "Cannot set cluster nodes to 'null'.");
116115

117116
this.clusterNodes.clear();
118117

@@ -137,7 +136,7 @@ public Set<RedisNode> getClusterNodes() {
137136
*/
138137
public void addClusterNode(RedisNode node) {
139138

140-
notNull(node, "ClusterNode must not be 'null'.");
139+
Assert.notNull(node, "ClusterNode must not be 'null'.");
141140
this.clusterNodes.add(node);
142141
}
143142

@@ -266,8 +265,8 @@ private RedisNode readHostAndPortFromString(String hostAndPort) {
266265

267266
String[] args = split(hostAndPort, ":");
268267

269-
notNull(args, "HostAndPort need to be seperated by ':'.");
270-
isTrue(args.length == 2, "Host and Port String needs to specified as host:port");
268+
Assert.notNull(args, "HostAndPort need to be seperated by ':'.");
269+
Assert.isTrue(args.length == 2, "Host and Port String needs to specified as host:port");
271270
return new RedisNode(args[0], Integer.valueOf(args[1]));
272271
}
273272

@@ -278,7 +277,8 @@ private RedisNode readHostAndPortFromString(String hostAndPort) {
278277
*/
279278
private static Map<String, Object> asMap(Collection<String> clusterHostAndPorts, int redirects) {
280279

281-
notNull(clusterHostAndPorts, "ClusterHostAndPorts must not be null!");
280+
Assert.notNull(clusterHostAndPorts, "ClusterHostAndPorts must not be null!");
281+
Assert.noNullElements(clusterHostAndPorts, "ClusterHostAndPorts must not contain null elements!");
282282

283283
Map<String, Object> map = new HashMap<>();
284284
map.put(REDIS_CLUSTER_NODES_CONFIG_PROPERTY, StringUtils.collectionToCommaDelimitedString(clusterHostAndPorts));

src/main/java/org/springframework/data/redis/connection/RedisSentinelConfiguration.java

+1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ private static Map<String, Object> asMap(String master, Set<String> sentinelHost
354354

355355
Assert.hasText(master, "Master address must not be null or empty!");
356356
Assert.notNull(sentinelHostAndPorts, "SentinelHostAndPorts must not be null!");
357+
Assert.noNullElements(sentinelHostAndPorts, "ClusterHostAndPorts must not contain null elements!");
357358

358359
Map<String, Object> map = new HashMap<>();
359360
map.put(REDIS_SENTINEL_MASTER_CONFIG_PROPERTY, master);

src/test/java/org/springframework/data/redis/connection/RedisClusterConfigurationUnitTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void shouldNotFailWhenGivenPropertySourceNotContainingRelevantProperties() {
9595
}
9696

9797
@Test // DATAREDIS-315
98-
void shouldBeCreatedCorrecltyGivenValidPropertySourceWithSingleHostPort() {
98+
void shouldBeCreatedCorrectlyGivenValidPropertySourceWithSingleHostPort() {
9999

100100
MockPropertySource propertySource = new MockPropertySource();
101101
propertySource.setProperty("spring.redis.cluster.nodes", HOST_AND_PORT_1);

0 commit comments

Comments
 (0)