Skip to content

Commit 3b1cb70

Browse files
committed
Polishing.
Add missing package info, fix invalid nullness annotations, reduce nullability. Add missing nullability annotations. Reformat code. Refine nullability flows and warnings. See #3092 Original pull request: #3159
1 parent f3fece9 commit 3b1cb70

File tree

249 files changed

+934
-702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+934
-702
lines changed

src/main/java/org/springframework/data/redis/ClusterRedirectException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
*/
3131
public class ClusterRedirectException extends DataRetrievalFailureException {
3232

33-
@Serial
34-
private static final long serialVersionUID = -857075813794333965L;
33+
private static final @Serial long serialVersionUID = -857075813794333965L;
3534

3635
private final int slot;
3736
private final String host;

src/main/java/org/springframework/data/redis/ClusterStateFailureException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
*/
3232
public class ClusterStateFailureException extends DataAccessResourceFailureException {
3333

34-
@Serial
35-
private static final long serialVersionUID = 333399051713240852L;
34+
private static final @Serial long serialVersionUID = 333399051713240852L;
3635

3736
/**
3837
* Creates new {@link ClusterStateFailureException}.

src/main/java/org/springframework/data/redis/TooManyClusterRedirectionsException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
*/
2929
public class TooManyClusterRedirectionsException extends DataRetrievalFailureException {
3030

31-
@Serial
32-
private static final long serialVersionUID = -2818933672669154328L;
31+
private static final @Serial long serialVersionUID = -2818933672669154328L;
3332

3433
/**
3534
* Creates new {@link TooManyClusterRedirectionsException}.

src/main/java/org/springframework/data/redis/aot/RedisRuntimeHints.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
174174
registerRedisConnectionProxy(TypeReference.of(RedisZSetCommands.class), hints);
175175
}
176176

177-
static void boundOperationsProxy(Class<?> type, ClassLoader classLoader, RuntimeHints hints) {
177+
static void boundOperationsProxy(Class<?> type, @Nullable ClassLoader classLoader, RuntimeHints hints) {
178178
boundOperationsProxy(TypeReference.of(type), classLoader, hints);
179179
}
180180

181-
static void boundOperationsProxy(TypeReference typeReference, ClassLoader classLoader, RuntimeHints hints) {
181+
static void boundOperationsProxy(TypeReference typeReference, @Nullable ClassLoader classLoader, RuntimeHints hints) {
182182

183183
String boundTargetClass = typeReference.getPackageName() + "." + typeReference.getSimpleName().replace("Bound", "");
184184
if (ClassUtils.isPresent(boundTargetClass, classLoader)) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* AOT Runtime hints.
19+
*/
20+
@org.jspecify.annotations.NullMarked
21+
package org.springframework.data.redis.aot;

src/main/java/org/springframework/data/redis/cache/BatchStrategies.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Optional;
2424

2525
import org.springframework.data.redis.connection.RedisConnection;
26+
import org.springframework.data.redis.connection.RedisKeyCommands;
2627
import org.springframework.data.redis.core.Cursor;
2728
import org.springframework.data.redis.core.ScanOptions;
2829
import org.springframework.util.Assert;
@@ -79,11 +80,13 @@ static class Keys implements BatchStrategy {
7980
@Override
8081
public long cleanCache(RedisConnection connection, String name, byte[] pattern) {
8182

82-
byte[][] keys = Optional.ofNullable(connection.keys(pattern)).orElse(Collections.emptySet())
83+
RedisKeyCommands commands = connection.keyCommands();
84+
85+
byte[][] keys = Optional.ofNullable(commands.keys(pattern)).orElse(Collections.emptySet())
8386
.toArray(new byte[0][]);
8487

8588
if (keys.length > 0) {
86-
connection.del(keys);
89+
commands.del(keys);
8790
}
8891

8992
return keys.length;
@@ -104,7 +107,9 @@ static class Scan implements BatchStrategy {
104107
@Override
105108
public long cleanCache(RedisConnection connection, String name, byte[] pattern) {
106109

107-
Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().count(batchSize).match(pattern).build());
110+
RedisKeyCommands commands = connection.keyCommands();
111+
112+
Cursor<byte[]> cursor = commands.scan(ScanOptions.scanOptions().count(batchSize).match(pattern).build());
108113

109114
long count = 0;
110115

@@ -116,8 +121,8 @@ public long cleanCache(RedisConnection connection, String name, byte[] pattern)
116121

117122
count += keys.size();
118123

119-
if (keys.size() > 0) {
120-
connection.del(keys.toArray(new byte[0][]));
124+
if (!keys.isEmpty()) {
125+
commands.del(keys.toArray(new byte[0][]));
121126
}
122127
}
123128

src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,25 +129,24 @@ class DefaultRedisCacheWriter implements RedisCacheWriter {
129129
}
130130

131131
@Override
132-
public byte[] get(String name, byte[] key) {
132+
public byte @Nullable [] get(String name, byte[] key) {
133133
return get(name, key, null);
134134
}
135135

136136
@Override
137-
public byte[] get(String name, byte[] key, @Nullable Duration ttl) {
137+
public byte @Nullable [] get(String name, byte[] key, @Nullable Duration ttl) {
138138

139139
Assert.notNull(name, "Name must not be null");
140140
Assert.notNull(key, "Key must not be null");
141141

142142
return execute(name, connection -> doGet(connection, name, key, ttl));
143143
}
144144

145-
146145
@SuppressWarnings("NullAway")
147146
private byte @Nullable[] doGet(RedisConnection connection, String name, byte[] key, @Nullable Duration ttl) {
148147

149-
byte[] result = shouldExpireWithin(ttl) ? connection.stringCommands().getEx(key, Expiration.from(ttl))
150-
: connection.stringCommands().get(key);
148+
RedisStringCommands commands = connection.stringCommands();
149+
byte[] result = shouldExpireWithin(ttl) ? commands.getEx(key, Expiration.from(ttl)) : commands.get(key);
151150

152151
statistics.incGets(name);
153152

src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,12 @@ public boolean isAllowRuntimeCacheCreation() {
326326
* Return an {@link Collections#unmodifiableMap(Map) unmodifiable Map} containing {@link String caches name} mapped to
327327
* the {@link RedisCache} {@link RedisCacheConfiguration configuration}.
328328
*
329-
* @return unmodifiable {@link Map} containing {@link String cache name}
330-
* / {@link RedisCacheConfiguration configuration} pairs.
329+
* @return unmodifiable {@link Map} containing {@link String cache name} to {@link RedisCacheConfiguration
330+
* configuration} pairs.
331331
*/
332-
public Map<String, RedisCacheConfiguration> getCacheConfigurations() {
332+
public Map<String, @Nullable RedisCacheConfiguration> getCacheConfigurations() {
333333

334-
Map<String, RedisCacheConfiguration> cacheConfigurationMap = new HashMap<>(getCacheNames().size());
334+
Map<String, @Nullable RedisCacheConfiguration> cacheConfigurationMap = new HashMap<>(getCacheNames().size());
335335

336336
getCacheNames().forEach(cacheName -> {
337337
RedisCache cache = (RedisCache) lookupCache(cacheName);
@@ -412,12 +412,29 @@ private RedisCacheConfiguration resolveCacheConfiguration(@Nullable RedisCacheCo
412412
*/
413413
public static class RedisCacheManagerBuilder {
414414

415+
private boolean allowRuntimeCacheCreation = true;
416+
private boolean enableTransactions;
417+
418+
private CacheStatisticsCollector statisticsCollector = CacheStatisticsCollector.none();
419+
420+
private final Map<String, RedisCacheConfiguration> initialCaches = new LinkedHashMap<>();
421+
422+
private RedisCacheConfiguration defaultCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
423+
424+
private @Nullable RedisCacheWriter cacheWriter;
425+
426+
private RedisCacheManagerBuilder() {}
427+
428+
private RedisCacheManagerBuilder(RedisCacheWriter cacheWriter) {
429+
this.cacheWriter = cacheWriter;
430+
}
431+
415432
/**
416433
* Factory method returning a new {@literal Builder} used to create and configure a {@link RedisCacheManager} using
417434
* the given {@link RedisCacheWriter}.
418435
*
419-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
420-
* by executing appropriate Redis commands; must not be {@literal null}.
436+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing
437+
* appropriate Redis commands; must not be {@literal null}.
421438
* @return new {@link RedisCacheManagerBuilder}.
422439
* @throws IllegalArgumentException if the given {@link RedisCacheWriter} is {@literal null}.
423440
* @see org.springframework.data.redis.cache.RedisCacheWriter
@@ -433,8 +450,8 @@ public static RedisCacheManagerBuilder fromCacheWriter(RedisCacheWriter cacheWri
433450
* Factory method returning a new {@literal Builder} used to create and configure a {@link RedisCacheManager} using
434451
* the given {@link RedisConnectionFactory}.
435452
*
436-
* @param connectionFactory {@link RedisConnectionFactory} used by the {@link RedisCacheManager}
437-
* to acquire connections to Redis when performing {@link RedisCache} operations; must not be {@literal null}.
453+
* @param connectionFactory {@link RedisConnectionFactory} used by the {@link RedisCacheManager} to acquire
454+
* connections to Redis when performing {@link RedisCache} operations; must not be {@literal null}.
438455
* @return new {@link RedisCacheManagerBuilder}.
439456
* @throws IllegalArgumentException if the given {@link RedisConnectionFactory} is {@literal null}.
440457
* @see org.springframework.data.redis.connection.RedisConnectionFactory
@@ -448,23 +465,6 @@ public static RedisCacheManagerBuilder fromConnectionFactory(RedisConnectionFact
448465
return new RedisCacheManagerBuilder(cacheWriter);
449466
}
450467

451-
private boolean allowRuntimeCacheCreation = true;
452-
private boolean enableTransactions;
453-
454-
private CacheStatisticsCollector statisticsCollector = CacheStatisticsCollector.none();
455-
456-
private final Map<String, RedisCacheConfiguration> initialCaches = new LinkedHashMap<>();
457-
458-
private RedisCacheConfiguration defaultCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
459-
460-
private @Nullable RedisCacheWriter cacheWriter;
461-
462-
private RedisCacheManagerBuilder() {}
463-
464-
private RedisCacheManagerBuilder(RedisCacheWriter cacheWriter) {
465-
this.cacheWriter = cacheWriter;
466-
}
467-
468468
/**
469469
* Configure whether to allow cache creation at runtime.
470470
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public BitFieldSubCommands to(long value) {
232232
*/
233233
public static class BitFieldGetBuilder {
234234

235-
private BitFieldSubCommands ref;
235+
private final BitFieldSubCommands ref;
236236

237237
BitFieldGet get = new BitFieldGet();
238238

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
public class ClusterCommandExecutionFailureException extends UncategorizedDataAccessException {
3232

33-
@Serial private static final long serialVersionUID = 5727044227040368955L;
33+
private static final @Serial long serialVersionUID = 5727044227040368955L;
3434

3535
/**
3636
* Creates new {@link ClusterCommandExecutionFailureException}.

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

Lines changed: 5 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,7 @@
1515
*/
1616
package org.springframework.data.redis.connection;
1717

18-
import java.util.ArrayList;
19-
import java.util.Arrays;
20-
import java.util.Collection;
21-
import java.util.Collections;
22-
import java.util.Comparator;
23-
import java.util.HashMap;
24-
import java.util.Iterator;
25-
import java.util.LinkedHashMap;
26-
import java.util.List;
27-
import java.util.Map;
28-
import java.util.Objects;
29-
import java.util.Random;
30-
import java.util.TreeMap;
18+
import java.util.*;
3119
import java.util.concurrent.Callable;
3220
import java.util.concurrent.ExecutionException;
3321
import java.util.concurrent.Future;
@@ -37,6 +25,7 @@
3725
import java.util.stream.Collectors;
3826

3927
import org.jspecify.annotations.Nullable;
28+
4029
import org.springframework.beans.factory.DisposableBean;
4130
import org.springframework.core.task.AsyncTaskExecutor;
4231
import org.springframework.core.task.SimpleAsyncTaskExecutor;
@@ -706,15 +695,7 @@ public int compare(PositionalKey o1, PositionalKey o2) {
706695
* @author Christoph Strobl
707696
* @since 2.0.3
708697
*/
709-
private static class PositionalKey {
710-
711-
private final ByteArrayWrapper key;
712-
private final int position;
713-
714-
private PositionalKey(ByteArrayWrapper key, int position) {
715-
this.key = key;
716-
this.position = position;
717-
}
698+
private record PositionalKey(ByteArrayWrapper key, int position) {
718699

719700
static PositionalKey of(byte[] key, int index) {
720701
return new PositionalKey(new ByteArrayWrapper(key), index);
@@ -724,36 +705,9 @@ static PositionalKey of(byte[] key, int index) {
724705
* @return binary key.
725706
*/
726707
byte[] getBytes() {
727-
return getKey().getArray();
728-
}
729-
730-
public ByteArrayWrapper getKey() {
731-
return this.key;
732-
}
733-
734-
public int getPosition() {
735-
return this.position;
736-
}
737-
738-
@Override
739-
public boolean equals(@Nullable Object obj) {
740-
741-
if (this == obj) {
742-
return true;
743-
}
744-
745-
if (!(obj instanceof PositionalKey that))
746-
return false;
747-
748-
return this.getPosition() == that.getPosition() && ObjectUtils.nullSafeEquals(this.getKey(), that.getKey());
708+
return key().getArray();
749709
}
750710

751-
@Override
752-
public int hashCode() {
753-
int result = ObjectUtils.nullSafeHashCode(getKey());
754-
result = 31 * result + ObjectUtils.nullSafeHashCode(getPosition());
755-
return result;
756-
}
757711
}
758712

759713
/**
@@ -763,13 +717,7 @@ public int hashCode() {
763717
* @author Christoph Strobl
764718
* @since 2.0.3
765719
*/
766-
private static class PositionalKeys implements Iterable<PositionalKey> {
767-
768-
private final List<PositionalKey> keys;
769-
770-
private PositionalKeys(List<PositionalKey> keys) {
771-
this.keys = keys;
772-
}
720+
private record PositionalKeys(List<PositionalKey> keys) implements Iterable<PositionalKey> {
773721

774722
/**
775723
* Create an empty {@link PositionalKeys}.

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,19 @@
3131
public class ClusterInfo {
3232

3333
public static enum Info {
34-
STATE("cluster_state"), SLOTS_ASSIGNED("cluster_slots_assigned"), SLOTS_OK("cluster_slots_ok"), SLOTS_PFAIL(
35-
"cluster_slots_pfail"), SLOTS_FAIL("cluster_slots_fail"), KNOWN_NODES("cluster_known_nodes"), SIZE(
36-
"cluster_size"), CURRENT_EPOCH("cluster_current_epoch"), MY_EPOCH("cluster_my_epoch"), MESSAGES_SENT(
37-
"cluster_stats_messages_sent"), MESSAGES_RECEIVED("cluster_stats_messages_received");
38-
39-
String key;
34+
STATE("cluster_state"), //
35+
SLOTS_ASSIGNED("cluster_slots_assigned"), //
36+
SLOTS_OK("cluster_slots_ok"), //
37+
SLOTS_PFAIL("cluster_slots_pfail"), //
38+
SLOTS_FAIL("cluster_slots_fail"), //
39+
KNOWN_NODES("cluster_known_nodes"), //
40+
SIZE("cluster_size"), //
41+
CURRENT_EPOCH("cluster_current_epoch"), //
42+
MY_EPOCH("cluster_my_epoch"), //
43+
MESSAGES_SENT("cluster_stats_messages_sent"), //
44+
MESSAGES_RECEIVED("cluster_stats_messages_received");
45+
46+
final String key;
4047

4148
Info(String key) {
4249
this.key = key;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public RedisClusterNode lookup(RedisClusterNode node) {
203203
}
204204

205205
if (node.hasValidHost() && node.getPort() != null) {
206-
return lookup(node.getHost(), node.getPort());
206+
return lookup(node.getRequiredHost(), node.getRequiredPort());
207207
}
208208

209209
if (StringUtils.hasText(node.getId())) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public DefaultSortParameters(byte @Nullable[] byPattern, @Nullable Range limit,
7171
setGetPattern(getPattern);
7272
}
7373

74-
7574
public byte @Nullable[] getByPattern() {
7675
return byPattern;
7776
}

0 commit comments

Comments
 (0)