Skip to content

Commit f3fece9

Browse files
christophstroblmp911de
authored andcommitted
Use to JSpecify for nullness checks.
Closes #3092 Original pull request: #3159
1 parent 0d09109 commit f3fece9

File tree

381 files changed

+4656
-5076
lines changed

Some content is hidden

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

381 files changed

+4656
-5076
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.Serial;
1919

20+
import org.jspecify.annotations.Nullable;
2021
import org.springframework.dao.DataRetrievalFailureException;
2122

2223
/**
@@ -44,7 +45,7 @@ public class ClusterRedirectException extends DataRetrievalFailureException {
4445
* @param targetPort the port on the host.
4546
* @param e the root cause from the data access API in use.
4647
*/
47-
public ClusterRedirectException(int slot, String targetHost, int targetPort, Throwable e) {
48+
public ClusterRedirectException(int slot, String targetHost, int targetPort, @Nullable Throwable e) {
4849

4950
super("Redirect: slot %s to %s:%s.".formatted(slot, targetHost, targetPort), e);
5051

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.Serial;
1919

20+
import org.jspecify.annotations.Nullable;
2021
import org.springframework.dao.DataAccessResourceFailureException;
2122

2223
/**
@@ -38,7 +39,7 @@ public class ClusterStateFailureException extends DataAccessResourceFailureExcep
3839
*
3940
* @param msg the detail message.
4041
*/
41-
public ClusterStateFailureException(String msg) {
42+
public ClusterStateFailureException(@Nullable String msg) {
4243
super(msg);
4344
}
4445

@@ -48,7 +49,7 @@ public ClusterStateFailureException(String msg) {
4849
* @param msg the detail message.
4950
* @param cause the nested exception.
5051
*/
51-
public ClusterStateFailureException(String msg, Throwable cause) {
52+
public ClusterStateFailureException(@Nullable String msg, @Nullable Throwable cause) {
5253
super(msg, cause);
5354
}
5455

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package org.springframework.data.redis;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.dao.DataAccessException;
19-
import org.springframework.lang.Nullable;
2020

2121
/**
2222
* Potentially translates an {@link Exception} into appropriate {@link DataAccessException}.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package org.springframework.data.redis;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.core.convert.converter.Converter;
1920
import org.springframework.dao.DataAccessException;
20-
import org.springframework.lang.Nullable;
2121

2222
/**
2323
* {@link PassThroughExceptionTranslationStrategy} returns {@literal null} for unknown {@link Exception}s.
@@ -34,9 +34,8 @@ public PassThroughExceptionTranslationStrategy(Converter<Exception, DataAccessEx
3434
this.converter = converter;
3535
}
3636

37-
@Nullable
3837
@Override
39-
public DataAccessException translate(Exception e) {
38+
public @Nullable DataAccessException translate(Exception e) {
4039
return this.converter.convert(e);
4140
}
4241

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

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

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.dao.DataAccessResourceFailureException;
1920

2021
/**
@@ -27,15 +28,15 @@ public class RedisConnectionFailureException extends DataAccessResourceFailureEx
2728
/**
2829
* @param msg the detail message.
2930
*/
30-
public RedisConnectionFailureException(String msg) {
31+
public RedisConnectionFailureException(@Nullable String msg) {
3132
super(msg);
3233
}
3334

3435
/**
3536
* @param msg the detail message.
3637
* @param cause the nested exception.
3738
*/
38-
public RedisConnectionFailureException(String msg, Throwable cause) {
39+
public RedisConnectionFailureException(@Nullable String msg, @Nullable Throwable cause) {
3940
super(msg, cause);
4041
}
4142

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

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

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.dao.UncategorizedDataAccessException;
19-
import org.springframework.lang.Nullable;
2020

2121
/**
2222
* Exception thrown when we can't classify a Redis exception into one of Spring generic data access exceptions.
@@ -29,7 +29,7 @@ public class RedisSystemException extends UncategorizedDataAccessException {
2929
* @param msg the detail message.
3030
* @param cause the root cause from the data access API in use.
3131
*/
32-
public RedisSystemException(String msg, @Nullable Throwable cause) {
32+
public RedisSystemException(@Nullable String msg, @Nullable Throwable cause) {
3333
super(msg, cause);
3434
}
3535

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.Serial;
1919

20+
import org.jspecify.annotations.Nullable;
2021
import org.springframework.dao.DataRetrievalFailureException;
2122

2223
/**
@@ -35,7 +36,7 @@ public class TooManyClusterRedirectionsException extends DataRetrievalFailureExc
3536
*
3637
* @param msg the detail message.
3738
*/
38-
public TooManyClusterRedirectionsException(String msg) {
39+
public TooManyClusterRedirectionsException(@Nullable String msg) {
3940
super(msg);
4041
}
4142

@@ -45,7 +46,7 @@ public TooManyClusterRedirectionsException(String msg) {
4546
* @param msg the detail message.
4647
* @param cause the root cause from the data access API in use.
4748
*/
48-
public TooManyClusterRedirectionsException(String msg, Throwable cause) {
49+
public TooManyClusterRedirectionsException(@Nullable String msg, @Nullable Throwable cause) {
4950
super(msg, cause);
5051
}
5152

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Arrays;
1919
import java.util.function.Consumer;
2020

21+
import org.jspecify.annotations.Nullable;
2122
import org.springframework.aot.hint.MemberCategory;
2223
import org.springframework.aot.hint.RuntimeHints;
2324
import org.springframework.aot.hint.RuntimeHintsRegistrar;
@@ -50,7 +51,6 @@
5051
import org.springframework.data.redis.repository.query.RedisPartTreeQuery;
5152
import org.springframework.data.redis.repository.query.RedisQueryCreator;
5253
import org.springframework.data.redis.repository.support.RedisRepositoryFactoryBean;
53-
import org.springframework.lang.Nullable;
5454
import org.springframework.util.ClassUtils;
5555

5656
/**

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.function.Function;
2929
import java.util.function.Supplier;
3030

31+
import org.jspecify.annotations.Nullable;
3132
import org.springframework.dao.PessimisticLockingFailureException;
3233
import org.springframework.data.redis.connection.ReactiveRedisConnection;
3334
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
@@ -38,7 +39,6 @@
3839
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
3940
import org.springframework.data.redis.core.types.Expiration;
4041
import org.springframework.data.redis.util.ByteUtils;
41-
import org.springframework.lang.Nullable;
4242
import org.springframework.util.Assert;
4343
import org.springframework.util.ClassUtils;
4444
import org.springframework.util.ObjectUtils;
@@ -142,8 +142,9 @@ public byte[] get(String name, byte[] key, @Nullable Duration ttl) {
142142
return execute(name, connection -> doGet(connection, name, key, ttl));
143143
}
144144

145-
@Nullable
146-
private byte[] doGet(RedisConnection connection, String name, byte[] key, @Nullable Duration ttl) {
145+
146+
@SuppressWarnings("NullAway")
147+
private byte @Nullable[] doGet(RedisConnection connection, String name, byte[] key, @Nullable Duration ttl) {
147148

148149
byte[] result = shouldExpireWithin(ttl) ? connection.stringCommands().getEx(key, Expiration.from(ttl))
149150
: connection.stringCommands().get(key);
@@ -241,6 +242,7 @@ public void put(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
241242

242243
}
243244

245+
@SuppressWarnings("NullAway")
244246
private void doPut(RedisConnection connection, String name, byte[] key, byte[] value, @Nullable Duration ttl) {
245247

246248
if (shouldExpireWithin(ttl)) {
@@ -265,6 +267,7 @@ public CompletableFuture<Void> store(String name, byte[] key, byte[] value, @Nul
265267
}
266268

267269
@Override
270+
@SuppressWarnings("NullAway")
268271
public byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl) {
269272

270273
Assert.notNull(name, "Name must not be null");
@@ -538,6 +541,7 @@ public boolean isSupported() {
538541
}
539542

540543
@Override
544+
@SuppressWarnings("NullAway")
541545
public CompletableFuture<byte[]> retrieve(String name, byte[] key, @Nullable Duration ttl) {
542546

543547
return doWithConnection(connection -> {
@@ -572,6 +576,7 @@ private Mono<Boolean> doStoreWithLocking(String name, byte[] key, byte[] value,
572576
unused -> doUnlock(name, connection));
573577
}
574578

579+
@SuppressWarnings("NullAway")
575580
private Mono<Boolean> doStore(byte[] cacheKey, byte[] value, @Nullable Duration ttl,
576581
ReactiveRedisConnection connection) {
577582

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import java.time.Duration;
1919

20+
import org.jspecify.annotations.Nullable;
2021
import org.springframework.data.redis.cache.RedisCacheWriter.TtlFunction;
21-
import org.springframework.lang.Nullable;
2222

2323
/**
2424
* {@link TtlFunction} implementation returning the given, predetermined {@link Duration} used for per cache entry

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.time.Instant;
1919
import java.util.concurrent.TimeUnit;
2020

21-
import org.springframework.lang.Nullable;
21+
import org.jspecify.annotations.Nullable;
2222
import org.springframework.util.ObjectUtils;
2323

2424
/**

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.concurrent.CompletableFuture;
2828
import java.util.function.Supplier;
2929

30+
import org.jspecify.annotations.Nullable;
3031
import org.springframework.cache.Cache;
3132
import org.springframework.cache.support.AbstractValueAdaptingCache;
3233
import org.springframework.cache.support.NullValue;
@@ -37,7 +38,6 @@
3738
import org.springframework.data.redis.serializer.RedisSerializationContext;
3839
import org.springframework.data.redis.serializer.RedisSerializer;
3940
import org.springframework.data.redis.util.ByteUtils;
40-
import org.springframework.lang.Nullable;
4141
import org.springframework.util.Assert;
4242
import org.springframework.util.ObjectUtils;
4343
import org.springframework.util.ReflectionUtils;
@@ -57,6 +57,7 @@
5757
@SuppressWarnings("unused")
5858
public class RedisCache extends AbstractValueAdaptingCache {
5959

60+
@SuppressWarnings("NullAway")
6061
static final byte[] BINARY_NULL_VALUE = RedisSerializer.java().serialize(NullValue.INSTANCE);
6162

6263
static final String CACHE_RETRIEVAL_UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE = "The Redis driver configured with RedisCache through RedisCacheWriter does not support CompletableFuture-based retrieval";
@@ -146,7 +147,7 @@ public CacheStatistics getStatistics() {
146147

147148
@Override
148149
@SuppressWarnings("unchecked")
149-
public <T> T get(Object key, Callable<T> valueLoader) {
150+
public <T> @Nullable T get(Object key, Callable<T> valueLoader) {
150151

151152
byte[] binaryKey = createAndConvertCacheKey(key);
152153
byte[] binaryValue = getCacheWriter().get(getName(), binaryKey,
@@ -176,7 +177,7 @@ protected <T> T loadCacheValue(Object key, Callable<T> valueLoader) {
176177
}
177178

178179
@Override
179-
protected Object lookup(Object key) {
180+
protected @Nullable Object lookup(Object key) {
180181

181182
byte[] binaryKey = createAndConvertCacheKey(key);
182183

@@ -196,6 +197,7 @@ private Duration getTimeToLive(Object key, @Nullable Object value) {
196197
}
197198

198199
@Override
200+
@SuppressWarnings("NullAway")
199201
public void put(Object key, @Nullable Object value) {
200202

201203
Object cacheValue = processAndCheckValue(value);
@@ -209,7 +211,8 @@ public void put(Object key, @Nullable Object value) {
209211
}
210212

211213
@Override
212-
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
214+
@SuppressWarnings("NullAway")
215+
public @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
213216

214217
Object cacheValue = preProcessCacheValue(value);
215218

@@ -268,7 +271,7 @@ public CompletableFuture<ValueWrapper> retrieve(Object key) {
268271
}
269272

270273
@Override
271-
@SuppressWarnings("unchecked")
274+
@SuppressWarnings({"unchecked", "NullAway"})
272275
public <T> CompletableFuture<T> retrieve(Object key, Supplier<CompletableFuture<T>> valueLoader) {
273276

274277
return retrieve(key).thenCompose(wrapper -> {
@@ -291,7 +294,7 @@ public <T> CompletableFuture<T> retrieve(Object key, Supplier<CompletableFuture<
291294
});
292295
}
293296

294-
private Object processAndCheckValue(@Nullable Object value) {
297+
private @Nullable Object processAndCheckValue(@Nullable Object value) {
295298

296299
Object cacheValue = preProcessCacheValue(value);
297300

@@ -311,8 +314,7 @@ private Object processAndCheckValue(@Nullable Object value) {
311314
* @param value can be {@literal null}.
312315
* @return preprocessed value. Can be {@literal null}.
313316
*/
314-
@Nullable
315-
protected Object preProcessCacheValue(@Nullable Object value) {
317+
protected @Nullable Object preProcessCacheValue(@Nullable Object value) {
316318
return value != null ? value : isAllowNullValues() ? NullValue.INSTANCE : null;
317319
}
318320

@@ -351,8 +353,7 @@ protected byte[] serializeCacheValue(Object value) {
351353
* {@link RedisSerializationContext.SerializationPair}; can be {@literal null}.
352354
* @see RedisCacheConfiguration#getValueSerializationPair()
353355
*/
354-
@Nullable
355-
protected Object deserializeCacheValue(byte[] value) {
356+
protected @Nullable Object deserializeCacheValue(byte[] value) {
356357

357358
if (isAllowNullValues() && ObjectUtils.nullSafeEquals(value, BINARY_NULL_VALUE)) {
358359
return NullValue.INSTANCE;
@@ -381,6 +382,7 @@ protected String createCacheKey(Object key) {
381382
* @return never {@literal null}.
382383
* @throws IllegalStateException if {@code key} cannot be converted to {@link String}.
383384
*/
385+
@SuppressWarnings("NullAway")
384386
protected String convertKey(Object key) {
385387

386388
if (key instanceof String stringKey) {
@@ -425,8 +427,7 @@ private CompletableFuture<ValueWrapper> retrieveValue(Object key) {
425427
.thenApply(this::toValueWrapper);
426428
}
427429

428-
@Nullable
429-
private Object nullSafeDeserializedStoreValue(@Nullable byte[] value) {
430+
private @Nullable Object nullSafeDeserializedStoreValue(byte @Nullable[] value) {
430431
return value != null ? fromStoreValue(deserializeCacheValue(value)) : null;
431432
}
432433

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.time.Duration;
2020
import java.util.function.Consumer;
2121

22+
import org.jspecify.annotations.Nullable;
2223
import org.springframework.cache.Cache;
2324
import org.springframework.cache.interceptor.SimpleKey;
2425
import org.springframework.core.convert.ConversionService;
@@ -28,7 +29,6 @@
2829
import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
2930
import org.springframework.data.redis.serializer.RedisSerializer;
3031
import org.springframework.format.support.DefaultFormattingConversionService;
31-
import org.springframework.lang.Nullable;
3232
import org.springframework.util.Assert;
3333

3434
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
import java.util.Optional;
2424
import java.util.Set;
2525

26+
import org.jspecify.annotations.Nullable;
2627
import org.springframework.cache.Cache;
2728
import org.springframework.cache.CacheManager;
2829
import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager;
2930
import org.springframework.data.redis.connection.RedisConnectionFactory;
30-
import org.springframework.lang.Nullable;
3131
import org.springframework.util.Assert;
3232

3333
/**
@@ -374,7 +374,7 @@ protected RedisCacheWriter getCacheWriter() {
374374
}
375375

376376
@Override
377-
protected RedisCache getMissingCache(String name) {
377+
protected @Nullable RedisCache getMissingCache(String name) {
378378
return isAllowRuntimeCacheCreation() ? createRedisCache(name, getDefaultCacheConfiguration()) : null;
379379
}
380380

0 commit comments

Comments
 (0)