Skip to content

Commit de93290

Browse files
committed
Reliable null value handling in ConcurrentMapCache, GuavaCache, JCacheCache
The 4.1 variant of this fix just introduces readResolve declarations to the existing NullHolder classes. Issue: SPR-13553
1 parent 57125c0 commit de93290

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import org.springframework.util.Assert;
2929

3030
/**
31-
* Spring {@link Cache} adapter implementation on top of a
32-
* Guava {@link com.google.common.cache.Cache} instance.
31+
* Spring {@link org.springframework.cache.Cache} adapter implementation
32+
* on top of a Guava {@link com.google.common.cache.Cache} instance.
3333
*
3434
* <p>Requires Google Guava 12.0 or higher.
3535
*
@@ -174,6 +174,10 @@ private ValueWrapper toWrapper(Object value) {
174174

175175
@SuppressWarnings("serial")
176176
private static class NullHolder implements Serializable {
177+
178+
private Object readResolve() {
179+
return NULL_HOLDER;
180+
}
177181
}
178182

179183

spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -142,6 +142,10 @@ protected Object toStoreValue(Object userValue) {
142142

143143
@SuppressWarnings("serial")
144144
private static class NullHolder implements Serializable {
145+
146+
private Object readResolve() {
147+
return NULL_HOLDER;
148+
}
145149
}
146150

147151
}

spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import org.springframework.util.Assert;
2626

2727
/**
28-
* Simple {@link Cache} implementation based on the core JDK
29-
* {@code java.util.concurrent} package.
28+
* Simple {@link org.springframework.cache.Cache} implementation based on the
29+
* core JDK {@code java.util.concurrent} package.
3030
*
3131
* <p>Useful for testing or simple caching scenarios, typically in combination
3232
* with {@link org.springframework.cache.support.SimpleCacheManager} or
@@ -172,6 +172,10 @@ private ValueWrapper toWrapper(Object value) {
172172

173173
@SuppressWarnings("serial")
174174
private static class NullHolder implements Serializable {
175+
176+
private Object readResolve() {
177+
return NULL_HOLDER;
178+
}
175179
}
176180

177181
}

0 commit comments

Comments
 (0)