Skip to content

Commit 3f42eda

Browse files
committed
Guard RedisClusterConfiguration.asMap and RedisSentinelConfiguration.asMap with Assert.noNullElements(…).
Closes #2167
1 parent 1652e02 commit 3f42eda

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

Lines changed: 7 additions & 7 deletions
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;
@@ -90,7 +89,7 @@ public RedisClusterConfiguration(Collection<String> clusterNodes) {
9089
*/
9190
public RedisClusterConfiguration(PropertySource<?> propertySource) {
9291

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

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

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

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

116115
this.clusterNodes.clear();
117116

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

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

@@ -227,8 +226,8 @@ private RedisNode readHostAndPortFromString(String hostAndPort) {
227226

228227
String[] args = split(hostAndPort, ":");
229228

230-
notNull(args, "HostAndPort need to be seperated by ':'.");
231-
isTrue(args.length == 2, "Host and Port String needs to specified as host:port");
229+
Assert.notNull(args, "HostAndPort need to be seperated by ':'.");
230+
Assert.isTrue(args.length == 2, "Host and Port String needs to specified as host:port");
232231
return new RedisNode(args[0], Integer.valueOf(args[1]));
233232
}
234233

@@ -239,7 +238,8 @@ private RedisNode readHostAndPortFromString(String hostAndPort) {
239238
*/
240239
private static Map<String, Object> asMap(Collection<String> clusterHostAndPorts, int redirects) {
241240

242-
notNull(clusterHostAndPorts, "ClusterHostAndPorts must not be null!");
241+
Assert.notNull(clusterHostAndPorts, "ClusterHostAndPorts must not be null!");
242+
Assert.noNullElements(clusterHostAndPorts, "ClusterHostAndPorts must not contain null elements!");
243243

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ private static Map<String, Object> asMap(String master, Set<String> sentinelHost
307307

308308
Assert.hasText(master, "Master address must not be null or empty!");
309309
Assert.notNull(sentinelHostAndPorts, "SentinelHostAndPorts must not be null!");
310+
Assert.noNullElements(sentinelHostAndPorts, "ClusterHostAndPorts must not contain null elements!");
310311

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

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

Lines changed: 1 addition & 1 deletion
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)