Skip to content

Commit c998abf

Browse files
DATAREDIS-481 - Remove reflective NullValue instance lookup.
Related issue: SPR-15693
1 parent d52fe24 commit c998abf

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

Diff for: src/main/java/org/springframework/data/redis/cache/RedisCache.java

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

18-
import java.lang.reflect.Field;
1918
import java.nio.ByteBuffer;
2019
import java.nio.charset.Charset;
2120
import java.util.concurrent.Callable;
@@ -29,7 +28,6 @@
2928
import org.springframework.lang.Nullable;
3029
import org.springframework.util.Assert;
3130
import org.springframework.util.ObjectUtils;
32-
import org.springframework.util.ReflectionUtils;
3331

3432
/**
3533
* {@link org.springframework.cache.Cache} implementation using for Redis as underlying store.
@@ -39,23 +37,13 @@
3937
*/
4038
public class RedisCache extends AbstractValueAdaptingCache {
4139

42-
private static final NullValue NULL_VALUE;
43-
private static final byte[] BINARY_NULL_VALUE;
40+
private static final byte[] BINARY_NULL_VALUE = new JdkSerializationRedisSerializer().serialize(NullValue.INSTANCE);
4441

4542
private final String name;
4643
private final RedisCacheWriter cacheWriter;
4744
private final RedisCacheConfiguration cacheConfig;
4845
private final ConfigurableConversionService conversionService = new DefaultFormattingConversionService();
4946

50-
static {
51-
52-
Field field = ReflectionUtils.findField(NullValue.class, "INSTANCE");
53-
ReflectionUtils.makeAccessible(field);
54-
NULL_VALUE = NullValue.class.cast(ReflectionUtils.getField(field, null));
55-
56-
BINARY_NULL_VALUE = new JdkSerializationRedisSerializer().serialize(NULL_VALUE);
57-
}
58-
5947
/**
6048
* Create new {@link RedisCache}.
6149
*
@@ -183,7 +171,7 @@ protected Object preProcessCacheValue(@Nullable Object value) {
183171
return value;
184172
}
185173

186-
return isAllowNullValues() ? NULL_VALUE : null;
174+
return isAllowNullValues() ? NullValue.INSTANCE : null;
187175
}
188176

189177
/**
@@ -221,7 +209,7 @@ protected byte[] serializeCacheValue(Object value) {
221209
protected Object deserializeCacheValue(byte[] value) {
222210

223211
if (isAllowNullValues() && ObjectUtils.nullSafeEquals(value, BINARY_NULL_VALUE)) {
224-
return NULL_VALUE;
212+
return NullValue.INSTANCE;
225213
}
226214

227215
return cacheConfig.getValueSerializationPair().read(ByteBuffer.wrap(value));

0 commit comments

Comments
 (0)